Serialize combine-queued-commits for git-revision
When configuring the trigger_builds Builder in the Jenkins web interface, you can add the parameter "Pass-through Git Commit that was built". You could not configure this in a jobs.yml. This commit adds that functionality (both to the builder "trigger_builds " and the publisher "trigger_parameterized_builds"). I still want to be backwards compatible with the old version (true/false) and maintain the similarity with the svn-revision param. Which means that you can either configure it as git-revision: true/false or git-revision: combine-queued-commits: true/false There were no prior case of shared code between builders and publishers, so (by recommendation) I put the common logic in builders.py, and then imported it in publishers.py. I added thorough tests for the feature in the builders fixtures, and only a basic test in the publishers fixtures, as suggested. Change-Id: I72cdcae3fac1094ffcc9367369556b8bcbe2d5d7
This commit is contained in:
parent
915a36f449
commit
50bc586ec5
@ -43,6 +43,7 @@ from jenkins_jobs.errors import InvalidAttributeError
|
||||
from jenkins_jobs.errors import JenkinsJobsException
|
||||
from jenkins_jobs.errors import MissingAttributeError
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules.helpers import append_git_revision_config
|
||||
from jenkins_jobs.modules.helpers import cloudformation_init
|
||||
from jenkins_jobs.modules.helpers import cloudformation_region_dict
|
||||
from jenkins_jobs.modules.helpers import cloudformation_stack
|
||||
@ -382,8 +383,11 @@ def trigger_builds(parser, xml_parent, data):
|
||||
Plugin (optional)
|
||||
:arg bool svn-revision: Whether to pass the svn revision to the triggered
|
||||
job (optional)
|
||||
:arg bool git-revision: Whether to pass the git revision to the triggered
|
||||
job (optional)
|
||||
:arg dict git-revision: Passes git revision to the triggered job
|
||||
(optional).
|
||||
|
||||
* **combine-queued-commits** (bool): Whether to combine queued git
|
||||
hashes or not (default false)
|
||||
:arg bool block: whether to wait for the triggered jobs to finish or not
|
||||
(default false)
|
||||
:arg dict block-thresholds: Fail builds and/or mark as failed or unstable
|
||||
@ -485,12 +489,10 @@ def trigger_builds(parser, xml_parent, data):
|
||||
XML.SubElement(tconfigs,
|
||||
'hudson.plugins.parameterizedtrigger.'
|
||||
'SubversionRevisionBuildParameters')
|
||||
|
||||
if(project_def.get('git-revision')):
|
||||
params = XML.SubElement(tconfigs,
|
||||
'hudson.plugins.git.'
|
||||
'GitRevisionBuildParameters')
|
||||
combine = XML.SubElement(params, 'combineQueuedCommits')
|
||||
combine.text = 'false'
|
||||
append_git_revision_config(tconfigs, project_def['git-revision'])
|
||||
|
||||
if(project_def.get('same-node')):
|
||||
XML.SubElement(tconfigs,
|
||||
'hudson.plugins.parameterizedtrigger.'
|
||||
|
@ -426,6 +426,21 @@ def artifactory_repository(xml_parent, data, target):
|
||||
data.get('deploy-dynamic-mode', False)).lower()
|
||||
|
||||
|
||||
def append_git_revision_config(parent, config_def):
|
||||
params = XML.SubElement(
|
||||
parent, 'hudson.plugins.git.GitRevisionBuildParameters')
|
||||
|
||||
try:
|
||||
# If git-revision is a boolean, the get() will
|
||||
# throw an AttributeError
|
||||
combine_commits = str(
|
||||
config_def.get('combine-queued-commits', False)).lower()
|
||||
except AttributeError:
|
||||
combine_commits = 'false'
|
||||
|
||||
XML.SubElement(params, 'combineQueuedCommits').text = combine_commits
|
||||
|
||||
|
||||
def convert_mapping_to_xml(parent, data, mapping, fail_required=False):
|
||||
"""Convert mapping to XML
|
||||
|
||||
|
@ -38,6 +38,7 @@ from jenkins_jobs.errors import JenkinsJobsException
|
||||
from jenkins_jobs.errors import MissingAttributeError
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules import hudson_model
|
||||
from jenkins_jobs.modules.helpers import append_git_revision_config
|
||||
from jenkins_jobs.modules.helpers import artifactory_common_details
|
||||
from jenkins_jobs.modules.helpers import artifactory_deployment_patterns
|
||||
from jenkins_jobs.modules.helpers import artifactory_env_vars_patterns
|
||||
@ -350,9 +351,18 @@ def trigger_parameterized_builds(parser, xml_parent, data):
|
||||
:arg bool svn-revision: Pass svn revision to the triggered job (optional)
|
||||
:arg bool include-upstream: Include/pass through Upstream SVN Revisons.
|
||||
Only valid when 'svn-revision' is true. (default false)
|
||||
:arg bool git-revision: Pass git revision to the other job (optional)
|
||||
:arg dict git-revision: Passes git revision to the triggered job
|
||||
(optional).
|
||||
|
||||
* **combine-queued-commits** (bool): Whether to combine queued git
|
||||
hashes or not (default false)
|
||||
|
||||
:arg bool combine-queued-commits: Combine Queued git hashes. Only valid
|
||||
when 'git-revision' is true. (default false)
|
||||
|
||||
.. deprecated:: 1.4.0. Please use `combine-queued-commits` under the
|
||||
`git-revision` argument instead.
|
||||
|
||||
:arg dict boolean-parameters: Pass boolean parameters to the downstream
|
||||
jobs. Specify the name and boolean value mapping of the parameters.
|
||||
(optional)
|
||||
@ -446,11 +456,19 @@ def trigger_parameterized_builds(parser, xml_parent, data):
|
||||
properties = XML.SubElement(params, 'properties')
|
||||
properties.text = param_value
|
||||
elif param_type == 'git-revision' and param_value:
|
||||
params = XML.SubElement(tconfigs,
|
||||
'hudson.plugins.git.'
|
||||
'GitRevisionBuildParameters')
|
||||
XML.SubElement(params, 'combineQueuedCommits').text = str(
|
||||
project_def.get('combine-queued-commits', False)).lower()
|
||||
if 'combine-queued-commits' in project_def:
|
||||
logger.warn(
|
||||
"'combine-queued-commit' has moved to reside under "
|
||||
"'git-revision' configuration, please update your "
|
||||
"configs as support for this will be removed."
|
||||
)
|
||||
git_revision = {
|
||||
'combine-queued-commits':
|
||||
project_def['combine-queued-commits']
|
||||
}
|
||||
else:
|
||||
git_revision = project_def['git-revision']
|
||||
append_git_revision_config(tconfigs, git_revision)
|
||||
elif param_type == 'property-file':
|
||||
params = XML.SubElement(tconfigs,
|
||||
pt_prefix + 'FileBuildParameters')
|
||||
|
@ -5,6 +5,9 @@
|
||||
<configs>
|
||||
<hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
||||
<configs>
|
||||
<hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<combineQueuedCommits>true</combineQueuedCommits>
|
||||
</hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
|
||||
<propertiesFile>propfile.txt</propertiesFile>
|
||||
<failTriggerOnMissing>true</failTriggerOnMissing>
|
||||
|
@ -1,6 +1,8 @@
|
||||
builders:
|
||||
- trigger-builds:
|
||||
- project: "build_started"
|
||||
git-revision:
|
||||
combine-queued-commits: true
|
||||
property-file: propfile.txt
|
||||
block: true
|
||||
block-thresholds:
|
||||
|
16
tests/builders/fixtures/trigger-builds007.xml
Normal file
16
tests/builders/fixtures/trigger-builds007.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<hudson.plugins.parameterizedtrigger.TriggerBuilder>
|
||||
<configs>
|
||||
<hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
||||
<configs class="java.util.Collections$EmptyList"/>
|
||||
<projects>build_started</projects>
|
||||
<condition>ALWAYS</condition>
|
||||
<triggerWithNoParameters>false</triggerWithNoParameters>
|
||||
<buildAllNodesWithLabel>false</buildAllNodesWithLabel>
|
||||
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
||||
</configs>
|
||||
</hudson.plugins.parameterizedtrigger.TriggerBuilder>
|
||||
</builders>
|
||||
</project>
|
4
tests/builders/fixtures/trigger-builds007.yaml
Normal file
4
tests/builders/fixtures/trigger-builds007.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
builders:
|
||||
- trigger-builds:
|
||||
- project: "build_started"
|
||||
git-revision: false
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<hudson.plugins.parameterizedtrigger.BuildTrigger>
|
||||
<configs>
|
||||
<hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
||||
<configs class="java.util.Collections$EmptyList"/>
|
||||
<projects>fixture</projects>
|
||||
<condition>SUCCESS</condition>
|
||||
<triggerWithNoParameters>false</triggerWithNoParameters>
|
||||
</hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
||||
</configs>
|
||||
</hudson.plugins.parameterizedtrigger.BuildTrigger>
|
||||
</publishers>
|
||||
</project>
|
@ -0,0 +1,4 @@
|
||||
publishers:
|
||||
- trigger-parameterized-builds:
|
||||
- project: 'fixture'
|
||||
condition: SUCCESS
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<hudson.plugins.parameterizedtrigger.BuildTrigger>
|
||||
<configs>
|
||||
<hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
||||
<configs>
|
||||
<hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<combineQueuedCommits>true</combineQueuedCommits>
|
||||
</hudson.plugins.git.GitRevisionBuildParameters>
|
||||
</configs>
|
||||
<projects>fixture</projects>
|
||||
<condition>SUCCESS</condition>
|
||||
<triggerWithNoParameters>false</triggerWithNoParameters>
|
||||
</hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
||||
</configs>
|
||||
</hudson.plugins.parameterizedtrigger.BuildTrigger>
|
||||
</publishers>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
publishers:
|
||||
- trigger-parameterized-builds:
|
||||
- project: 'fixture'
|
||||
condition: SUCCESS
|
||||
git-revision:
|
||||
combine-queued-commits: true
|
@ -20,6 +20,9 @@ bar=foo
|
||||
<hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
||||
<properties>BUILD_NUM=${BUILD_NUMBER}</properties>
|
||||
</hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
||||
<hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<combineQueuedCommits>false</combineQueuedCommits>
|
||||
</hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
|
||||
<propertiesFile>version.prop</propertiesFile>
|
||||
<failTriggerOnMissing>true</failTriggerOnMissing>
|
||||
@ -35,7 +38,7 @@ bar=foo
|
||||
<properties>foo=bar</properties>
|
||||
</hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
||||
<hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<combineQueuedCommits>false</combineQueuedCommits>
|
||||
<combineQueuedCommits>true</combineQueuedCommits>
|
||||
</hudson.plugins.git.GitRevisionBuildParameters>
|
||||
<hudson.plugins.parameterizedtrigger.matrix.MatrixSubsetBuildParameters>
|
||||
<filter>label=="x86"</filter>
|
||||
|
@ -9,11 +9,13 @@ publishers:
|
||||
bar=foo
|
||||
- project: other_job1, other_job2
|
||||
predefined-parameters: BUILD_NUM=${BUILD_NUMBER}
|
||||
git-revision: true
|
||||
property-file: version.prop
|
||||
fail-on-missing: true
|
||||
- project: yet_another_job
|
||||
predefined-parameters: foo=bar
|
||||
git-revision: true
|
||||
git-revision:
|
||||
combine-queued-commits: true
|
||||
restrict-matrix-project: label=="x86"
|
||||
- project: yet_another_job_2
|
||||
node-label-name: foo
|
||||
|
@ -36,4 +36,4 @@
|
||||
</configs>
|
||||
</hudson.plugins.parameterizedtrigger.BuildTrigger>
|
||||
</publishers>
|
||||
</project>
|
||||
</project>
|
||||
|
Loading…
Reference in New Issue
Block a user