From e2cf69b4f4647ca8018eeec162ce106c4117303b Mon Sep 17 00:00:00 2001 From: Vsevolod Fedorov Date: Thu, 14 Dec 2023 11:58:31 +0300 Subject: [PATCH] Fix support for obsolete format of pre-scm-buildstep 'pre-scm-buildstep' wrapper has two modes: 1. Older: no 'buildsteps' element is specified. Build steps is a list under wrapper name. For example: - pre-scm-buildstep: - shell: echo hello - shell: echo bye 2. Newer: build steps specified inside 'buildsteps' mapping element: - pre-scm-buildsteps: buildsteps: - shell: echo hello - shell: echo bye But, when 'preSCMbuildstep' plugin version is equal or higher 0.3, and first mode is used, it fails. Fix that. Change-Id: I010d9f6c5e06ccd8c2723026aae2c60f79917ff4 --- jenkins_jobs/modules/wrappers.py | 2 +- ...-buildstep-no-buildsteps.plugins_info.yaml | 3 +++ .../pre-scm-buildstep-no-buildsteps.xml | 19 +++++++++++++++++++ .../pre-scm-buildstep-no-buildsteps.yaml | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.plugins_info.yaml create mode 100644 tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.xml create mode 100644 tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index b8f7eb8d6..85bc185c9 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1833,7 +1833,7 @@ def pre_scm_buildstep(registry, xml_parent, data): for step in stepList: for edited_node in create_builders(registry, step): bs.append(edited_node) - if version >= pkg_resources.parse_version("0.3"): + if version >= pkg_resources.parse_version("0.3") and not isinstance(data, list): mapping = [("failOnError", "failOnError", False)] helpers.convert_mapping_to_xml(bsp, data, mapping, fail_required=True) diff --git a/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.plugins_info.yaml b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.plugins_info.yaml new file mode 100644 index 000000000..ba9d78002 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Pre SCM BuildStep Plugin' + shortName: 'preSCMbuildstep' + version: "0.3" diff --git a/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.xml b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.xml new file mode 100644 index 000000000..3f2c11d86 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.xml @@ -0,0 +1,19 @@ + + + + + + + #!/bin/bash +echo "Doing something cool" + + + + #!/bin/zsh +echo "Doing something cool with zsh" + + + + + + diff --git a/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.yaml b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.yaml new file mode 100644 index 000000000..e9112e29d --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep-no-buildsteps.yaml @@ -0,0 +1,8 @@ +wrappers: + - pre-scm-buildstep: + - shell: | + #!/bin/bash + echo "Doing something cool" + - shell: | + #!/bin/zsh + echo "Doing something cool with zsh"