Retain user specified order of post build scripts
Avoid imposing hardcoded order of the scripts within the module and instead favour the order of the input data. Combined with use of ordered dicts for yaml, this ensures that users may control the order of the various steps to use with the post build scripts from yaml. Change-Id: Icf540a53cb6f1b13f80f09d9103610aee10d3861
This commit is contained in:
parent
2d74b16620
commit
c9ed6891cf
@ -2396,27 +2396,32 @@ postbuildscript003.yaml
|
|||||||
|
|
||||||
# Shell/Groovy in a file
|
# Shell/Groovy in a file
|
||||||
script_types = {
|
script_types = {
|
||||||
'generic': 'GenericScript',
|
'generic-script': 'GenericScript',
|
||||||
'groovy': 'GroovyScriptFile',
|
'groovy-script': 'GroovyScriptFile',
|
||||||
}
|
}
|
||||||
for script_type in sorted(script_types.keys()):
|
|
||||||
if script_type + '-script' not in data:
|
|
||||||
continue
|
|
||||||
|
|
||||||
scripts_xml = XML.SubElement(pbs_xml, script_type + 'ScriptFileList')
|
# Assuming yaml preserves order of input data make sure
|
||||||
for shell_scripts in [data.get(script_type + '-script', [])]:
|
# corresponding XML steps are generated in the same order
|
||||||
for shell_script in shell_scripts:
|
build_scripts = [(k, v) for k, v in data.items()
|
||||||
|
if k in script_types or k in ['groovy', 'builders']]
|
||||||
|
|
||||||
|
for step, script_data in build_scripts:
|
||||||
|
if step in script_types:
|
||||||
|
scripts_xml = XML.SubElement(pbs_xml, step[:-len('-script')] +
|
||||||
|
'ScriptFileList')
|
||||||
|
for shell_script in script_data:
|
||||||
script_xml = XML.SubElement(
|
script_xml = XML.SubElement(
|
||||||
scripts_xml,
|
scripts_xml,
|
||||||
'org.jenkinsci.plugins.postbuildscript.'
|
'org.jenkinsci.plugins.postbuildscript.'
|
||||||
+ script_types[script_type])
|
+ script_types[step])
|
||||||
file_path_xml = XML.SubElement(script_xml, 'filePath')
|
file_path_xml = XML.SubElement(script_xml, 'filePath')
|
||||||
file_path_xml.text = shell_script
|
file_path_xml.text = shell_script
|
||||||
|
|
||||||
# Inlined Groovy
|
# Inlined Groovy
|
||||||
if 'groovy' in data:
|
if step == 'groovy':
|
||||||
groovy_inline_xml = XML.SubElement(pbs_xml, 'groovyScriptContentList')
|
groovy_inline_xml = XML.SubElement(pbs_xml,
|
||||||
for groovy in data.get('groovy', []):
|
'groovyScriptContentList')
|
||||||
|
for groovy in script_data:
|
||||||
groovy_xml = XML.SubElement(
|
groovy_xml = XML.SubElement(
|
||||||
groovy_inline_xml,
|
groovy_inline_xml,
|
||||||
'org.jenkinsci.plugins.postbuildscript.GroovyScriptContent'
|
'org.jenkinsci.plugins.postbuildscript.GroovyScriptContent'
|
||||||
@ -2425,9 +2430,9 @@ postbuildscript003.yaml
|
|||||||
groovy_content.text = groovy
|
groovy_content.text = groovy
|
||||||
|
|
||||||
# Inject builders
|
# Inject builders
|
||||||
if 'builders' in data:
|
if step == 'builders':
|
||||||
build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps')
|
build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps')
|
||||||
for builder in data.get('builders', []):
|
for builder in script_data:
|
||||||
parser.registry.dispatch('builder', parser, build_steps_xml,
|
parser.registry.dispatch('builder', parser, build_steps_xml,
|
||||||
builder)
|
builder)
|
||||||
|
|
||||||
|
42
tests/publishers/fixtures/postbuildscript004.xml
Normal file
42
tests/publishers/fixtures/postbuildscript004.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project>
|
||||||
|
<publishers>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.PostBuildScript>
|
||||||
|
<buildSteps>
|
||||||
|
<hudson.tasks.Shell>
|
||||||
|
<command>echo "Shell execution should be first"</command>
|
||||||
|
</hudson.tasks.Shell>
|
||||||
|
<hudson.tasks.Ant>
|
||||||
|
<targets>ant_target</targets>
|
||||||
|
<antName>default</antName>
|
||||||
|
</hudson.tasks.Ant>
|
||||||
|
</buildSteps>
|
||||||
|
<groovyScriptContentList>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GroovyScriptContent>
|
||||||
|
<content>/** This is some inlined groovy */</content>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GroovyScriptContent>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GroovyScriptContent>
|
||||||
|
<content>/** Some more inlined groovy */</content>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GroovyScriptContent>
|
||||||
|
</groovyScriptContentList>
|
||||||
|
<genericScriptFileList>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GenericScript>
|
||||||
|
<filePath>/tmp/one.sh</filePath>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GenericScript>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GenericScript>
|
||||||
|
<filePath>/tmp/two.sh</filePath>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GenericScript>
|
||||||
|
</genericScriptFileList>
|
||||||
|
<groovyScriptFileList>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
|
||||||
|
<filePath>/tmp/one.groovy</filePath>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
|
||||||
|
<org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
|
||||||
|
<filePath>/tmp/two.groovy</filePath>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.GroovyScriptFile>
|
||||||
|
</groovyScriptFileList>
|
||||||
|
<scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
|
||||||
|
<scriptOnlyIfFailure>true</scriptOnlyIfFailure>
|
||||||
|
</org.jenkinsci.plugins.postbuildscript.PostBuildScript>
|
||||||
|
</publishers>
|
||||||
|
</project>
|
16
tests/publishers/fixtures/postbuildscript004.yaml
Normal file
16
tests/publishers/fixtures/postbuildscript004.yaml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
publishers:
|
||||||
|
- postbuildscript:
|
||||||
|
builders:
|
||||||
|
- shell: 'echo "Shell execution should be first"'
|
||||||
|
- ant: 'ant_target'
|
||||||
|
groovy:
|
||||||
|
- "/** This is some inlined groovy */"
|
||||||
|
- "/** Some more inlined groovy */"
|
||||||
|
generic-script:
|
||||||
|
- '/tmp/one.sh'
|
||||||
|
- '/tmp/two.sh'
|
||||||
|
groovy-script:
|
||||||
|
- '/tmp/one.groovy'
|
||||||
|
- '/tmp/two.groovy'
|
||||||
|
onsuccess: False
|
||||||
|
onfailure: True
|
Loading…
Reference in New Issue
Block a user