diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index f8c72e63b..0ecf9b92d 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -1402,33 +1402,34 @@ def pre_scm_buildstep(registry, xml_parent, data): Execute a Build Step before running the SCM Requires the Jenkins :jenkins-wiki:`pre-scm-buildstep `. + :arg string failOnError: Specifies if the job should fail on error + (plugin >= 0.3) (default false). :arg list buildsteps: List of build steps to execute :Buildstep: Any acceptable builder, as seen in the example - Example:: + Example: - wrappers: - - pre-scm-buildstep: - - shell: | - #!/bin/bash - echo "Doing somethiung cool" - - shell: | - #!/bin/zsh - echo "Doing somethin cool with zsh" - - ant: "target1 target2" - ant-name: "Standard Ant" - - inject: - properties-file: example.prop - properties-content: EXAMPLE=foo-bar + .. literalinclude:: + /../../tests/wrappers/fixtures/pre-scm-buildstep001.yaml + :language: yaml """ + # Get plugin information to maintain backwards compatibility + info = registry.get_plugin_info('preSCMbuildstep') + version = pkg_resources.parse_version(info.get('version', "0")) + bsp = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.preSCMbuildstep.' 'PreSCMBuildStepsWrapper') bs = XML.SubElement(bsp, 'buildSteps') - for step in data: + stepList = data if type(data) is list else data.get('buildsteps') + + for step in stepList: for edited_node in create_builders(registry, step): bs.append(edited_node) + if version >= pkg_resources.parse_version("0.3"): + XML.SubElement(bsp, 'failOnError').text = str(data.get( + 'failOnError', False)).lower() def logstash(registry, xml_parent, data): diff --git a/tests/cmd/fixtures/unicode001.yaml b/tests/cmd/fixtures/unicode001.yaml index a2bee1639..b1e45e352 100644 --- a/tests/cmd/fixtures/unicode001.yaml +++ b/tests/cmd/fixtures/unicode001.yaml @@ -2,9 +2,10 @@ name: unicode-wrapper wrappers: - pre-scm-buildstep: - - shell: | - #!/bin/bash - echo "Unicode! ☃" + buildsteps: + - shell: | + #!/bin/bash + echo "Unicode! ☃" - job: name: test-unicode-wrapper diff --git a/tests/jsonparser/fixtures/complete001.json b/tests/jsonparser/fixtures/complete001.json index 517e1cc2d..d6614b668 100644 --- a/tests/jsonparser/fixtures/complete001.json +++ b/tests/jsonparser/fixtures/complete001.json @@ -19,26 +19,28 @@ "name": "pre-scm-shell-ant", "wrappers": [ { - "pre-scm-buildstep": [ - { - "shell": "#!/bin/bash\necho \"Doing somethiung cool\"\n" - }, - { - "shell": "#!/bin/zsh\necho \"Doing somethin cool with zsh\"\n" - }, - { - "ant": { - "targets": "target1 target2", - "ant-name": "Standard Ant" + "pre-scm-buildstep": { + "buildsteps": [ + { + "shell": "#!/bin/bash\necho \"Doing somethiung cool\"\n" + }, + { + "shell": "#!/bin/zsh\necho \"Doing somethin cool with zsh\"\n" + }, + { + "ant": { + "targets": "target1 target2", + "ant-name": "Standard Ant" + } + }, + { + "inject": { + "properties-file": "example.prop", + "properties-content": "EXAMPLE=foo-bar" + } } - }, - { - "inject": { - "properties-file": "example.prop", - "properties-content": "EXAMPLE=foo-bar" - } - } - ] + ] + } } ] } @@ -165,4 +167,4 @@ ] } } -] \ No newline at end of file +] diff --git a/tests/wrappers/fixtures/pre-scm-buildstep001.plugins_info.yaml b/tests/wrappers/fixtures/pre-scm-buildstep001.plugins_info.yaml new file mode 100644 index 000000000..ba9d78002 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep001.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-buildstep001.xml b/tests/wrappers/fixtures/pre-scm-buildstep001.xml new file mode 100644 index 000000000..e29a60ba0 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep001.xml @@ -0,0 +1,30 @@ + + + + + + + #!/bin/bash +echo "Doing something cool" + + + + #!/bin/zsh +echo "Doing something cool with zsh" + + + + target1 target2 + default + + + + example.prop + EXAMPLE=foo-bar + + + + true + + + diff --git a/tests/wrappers/fixtures/pre-scm-buildstep001.yaml b/tests/wrappers/fixtures/pre-scm-buildstep001.yaml new file mode 100644 index 000000000..b5c17da5f --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep001.yaml @@ -0,0 +1,15 @@ +wrappers: + - pre-scm-buildstep: + failOnError: true + buildsteps: + - shell: | + #!/bin/bash + echo "Doing something cool" + - shell: | + #!/bin/zsh + echo "Doing something cool with zsh" + - ant: "target1 target2" + ant-name: "Standard Ant" + - inject: + properties-file: example.prop + properties-content: EXAMPLE=foo-bar diff --git a/tests/wrappers/fixtures/pre-scm-buildstep002.plugins_info.yaml b/tests/wrappers/fixtures/pre-scm-buildstep002.plugins_info.yaml new file mode 100644 index 000000000..8a139a777 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep002.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Pre SCM BuildStep Plugin' + shortName: 'preSCMbuildstep' + version: "0.2" diff --git a/tests/wrappers/fixtures/pre-scm-buildstep002.xml b/tests/wrappers/fixtures/pre-scm-buildstep002.xml new file mode 100644 index 000000000..3f2c11d86 --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep002.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-buildstep002.yaml b/tests/wrappers/fixtures/pre-scm-buildstep002.yaml new file mode 100644 index 000000000..e9112e29d --- /dev/null +++ b/tests/wrappers/fixtures/pre-scm-buildstep002.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" diff --git a/tests/yamlparser/fixtures/complete001.yaml b/tests/yamlparser/fixtures/complete001.yaml index 519095d6c..2a9ce7ec6 100644 --- a/tests/yamlparser/fixtures/complete001.yaml +++ b/tests/yamlparser/fixtures/complete001.yaml @@ -11,18 +11,19 @@ name: pre-scm-shell-ant wrappers: - pre-scm-buildstep: - - shell: | - #!/bin/bash - echo "Doing somethiung cool" - - shell: | - #!/bin/zsh - echo "Doing somethin cool with zsh" - - ant: - targets: "target1 target2" - ant-name: "Standard Ant" - - inject: - properties-file: example.prop - properties-content: EXAMPLE=foo-bar + buildsteps: + - shell: | + #!/bin/bash + echo "Doing somethiung cool" + - shell: | + #!/bin/zsh + echo "Doing somethin cool with zsh" + - ant: + targets: "target1 target2" + ant-name: "Standard Ant" + - inject: + properties-file: example.prop + properties-content: EXAMPLE=foo-bar - wrapper: name: copy-files @@ -104,4 +105,3 @@ #!/usr/bin/env python # print("Doing something cool with python") - diff --git a/tests/yamlparser/fixtures/include-raw001.yaml b/tests/yamlparser/fixtures/include-raw001.yaml index bff63ccd4..de5e44bb8 100644 --- a/tests/yamlparser/fixtures/include-raw001.yaml +++ b/tests/yamlparser/fixtures/include-raw001.yaml @@ -12,16 +12,17 @@ name: pre-scm-shell-ant wrappers: - pre-scm-buildstep: - - shell: - !include-raw: include-raw002-cool.sh - - shell: - !include-raw: include-raw002-cool.zsh - - ant: - targets: "target1 target2" - ant-name: "Standard Ant" - - inject: - properties-file: example.prop - properties-content: EXAMPLE=foo-bar + buildsteps: + - shell: + !include-raw: include-raw002-cool.sh + - shell: + !include-raw: include-raw002-cool.zsh + - ant: + targets: "target1 target2" + ant-name: "Standard Ant" + - inject: + properties-file: example.prop + properties-content: EXAMPLE=foo-bar - wrapper: name: copy-files @@ -42,4 +43,3 @@ - inject: keep-build-variables: true keep-system-variables: true - diff --git a/tests/yamlparser/fixtures/include-rawunicode001.yaml b/tests/yamlparser/fixtures/include-rawunicode001.yaml index e1379dc68..f74724027 100644 --- a/tests/yamlparser/fixtures/include-rawunicode001.yaml +++ b/tests/yamlparser/fixtures/include-rawunicode001.yaml @@ -2,8 +2,9 @@ name: unicode-raw-include-wrapper wrappers: - pre-scm-buildstep: - - shell: - !include-raw: include-rawunicode001-cool.sh + buildsteps: + - shell: + !include-raw: include-rawunicode001-cool.sh - job: name: test-unicode-raw-include-wrapper diff --git a/tests/yamlparser/fixtures/include001.yaml b/tests/yamlparser/fixtures/include001.yaml index 8c7c3cb08..515e11a87 100644 --- a/tests/yamlparser/fixtures/include001.yaml +++ b/tests/yamlparser/fixtures/include001.yaml @@ -12,17 +12,18 @@ name: pre-scm-shell-ant wrappers: - pre-scm-buildstep: - - shell: | - #!/bin/bash - echo "Doing somethiung cool" - - shell: | - #!/bin/zsh - echo "Doing somethin cool with zsh" - - ant: "target1 target2" - ant-name: "Standard Ant" - - inject: - properties-file: example.prop - properties-content: EXAMPLE=foo-bar + buildsteps: + - shell: | + #!/bin/bash + echo "Doing somethiung cool" + - shell: | + #!/bin/zsh + echo "Doing somethin cool with zsh" + - ant: "target1 target2" + ant-name: "Standard Ant" + - inject: + properties-file: example.prop + properties-content: EXAMPLE=foo-bar - wrapper: name: copy-files @@ -43,4 +44,3 @@ - inject: keep-build-variables: true keep-system-variables: true - diff --git a/tests/yamlparser/fixtures/unicode001.yaml b/tests/yamlparser/fixtures/unicode001.yaml index a2bee1639..b1e45e352 100644 --- a/tests/yamlparser/fixtures/unicode001.yaml +++ b/tests/yamlparser/fixtures/unicode001.yaml @@ -2,9 +2,10 @@ name: unicode-wrapper wrappers: - pre-scm-buildstep: - - shell: | - #!/bin/bash - echo "Unicode! ☃" + buildsteps: + - shell: | + #!/bin/bash + echo "Unicode! ☃" - job: name: test-unicode-wrapper