diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py
index dd58eddf3..f2c1e394f 100644
--- a/jenkins_jobs/modules/builders.py
+++ b/jenkins_jobs/modules/builders.py
@@ -262,6 +262,9 @@ def trigger_builds(parser, xml_parent, data):
key/value pairs to be passed to the job (optional)
:arg str property-file:
Pass properties from file to the other job (optional)
+ :arg bool property-file-fail-on-missing:
+ Don't trigger if any files are missing (optional)
+ (default true)
:arg bool current-parameters: Whether to include the
parameters passed to the current build to the
triggered job.
@@ -271,11 +274,45 @@ def trigger_builds(parser, xml_parent, data):
to finish or not (default false)
:arg bool same-node: Use the same node for the triggered builds that was
used for this build (optional)
+ :arg list parameter-factories: list of parameter factories
- Example:
+ :Factory: * **factory** (`str`) **filebuild** -- For every property file,
+ invoke one build
+ * **file-pattern** (`str`) -- File wildcard pattern
+ * **no-files-found-action** (`str`) -- Action to perform when
+ no files found (optional) ['FAIL', 'SKIP', 'NOPARMS']
+ (default 'SKIP')
+
+ :Factory: * **factory** (`str`) **binaryfile** -- For every matching
+ file, invoke one build
+ * **file-pattern** (`str`) -- Artifact ID of the artifact
+ * **no-files-found-action** (`str`) -- Action to perform when
+ no files found (optional) ['FAIL', 'SKIP', 'NOPARMS']
+ (default 'SKIP')
+
+ :Factory: * **factory** (`str`) **counterbuild** -- Invoke i=0...N builds
+ * **from** (`int`) -- Artifact ID of the artifact
+ * **to** (`int`) -- Version of the artifact
+ * **step** (`int`) -- Classifier of the artifact
+ * **parameters** (`str`) -- KEY=value pairs, one per line
+ (default '')
+ * **validation-fail** (`str`) -- Action to perform when
+ stepping validation fails (optional)
+ ['FAIL', 'SKIP', 'NOPARMS']
+ (default 'FAIL')
+
+ Examples:
+
+ Basic usage.
.. literalinclude:: /../../tests/builders/fixtures/trigger-builds001.yaml
:language: yaml
+
+ Example with all supported parameter factories.
+
+ .. literalinclude:: \
+ /../../tests/builders/fixtures/trigger-builds-configfactory-multi.yaml
+ :language: yaml
"""
tbuilder = XML.SubElement(xml_parent,
'hudson.plugins.parameterizedtrigger.'
@@ -307,8 +344,11 @@ def trigger_builds(parser, xml_parent, data):
'FileBuildParameters')
propertiesFile = XML.SubElement(params, 'propertiesFile')
propertiesFile.text = project_def['property-file']
- failOnMissing = XML.SubElement(params, 'failTriggerOnMissing')
- failOnMissing.text = 'true'
+ failTriggerOnMissing = XML.SubElement(params,
+ 'failTriggerOnMissing')
+ failTriggerOnMissing.text = str(project_def.get(
+ 'property-file-fail-on-missing', True)).lower()
+
if 'predefined-parameters' in project_def:
params = XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
@@ -317,6 +357,67 @@ def trigger_builds(parser, xml_parent, data):
properties.text = project_def['predefined-parameters']
if(len(list(tconfigs)) == 0):
tconfigs.set('class', 'java.util.Collections$EmptyList')
+
+ if 'parameter-factories' in project_def:
+ fconfigs = XML.SubElement(tconfig, 'configFactories')
+
+ supported_factories = ['filebuild', 'binaryfile', 'counterbuild']
+ supported_actions = ['SKIP', 'NOPARMS', 'FAIL']
+ for factory in project_def['parameter-factories']:
+
+ if factory['factory'] not in supported_factories:
+ raise JenkinsJobsException("factory must be one of %s" %
+ ", ".join(supported_factories))
+
+ if factory['factory'] == 'filebuild':
+ params = XML.SubElement(
+ fconfigs,
+ 'hudson.plugins.parameterizedtrigger.'
+ 'FileBuildParameterFactory')
+ if factory['factory'] == 'binaryfile':
+ params = XML.SubElement(
+ fconfigs,
+ 'hudson.plugins.parameterizedtrigger.'
+ 'BinaryFileParameterFactory')
+ parameterName = XML.SubElement(params, 'parameterName')
+ parameterName.text = factory['parameter-name']
+ if (factory['factory'] == 'filebuild' or
+ factory['factory'] == 'binaryfile'):
+ filePattern = XML.SubElement(params, 'filePattern')
+ filePattern.text = factory['file-pattern']
+ noFilesFoundAction = XML.SubElement(
+ params,
+ 'noFilesFoundAction')
+ noFilesFoundActionValue = str(factory.get(
+ 'no-files-found-action', 'SKIP'))
+ if noFilesFoundActionValue not in supported_actions:
+ raise JenkinsJobsException(
+ "no-files-found-action must be one of %s" %
+ ", ".join(supported_actions))
+ noFilesFoundAction.text = noFilesFoundActionValue
+ if factory['factory'] == 'counterbuild':
+ params = XML.SubElement(
+ fconfigs,
+ 'hudson.plugins.parameterizedtrigger.'
+ 'CounterBuildParameterFactory')
+ fromProperty = XML.SubElement(params, 'from')
+ fromProperty.text = str(factory['from'])
+ toProperty = XML.SubElement(params, 'to')
+ toProperty.text = str(factory['to'])
+ stepProperty = XML.SubElement(params, 'step')
+ stepProperty.text = str(factory['step'])
+ paramExpr = XML.SubElement(params, 'paramExpr')
+ paramExpr.text = str(factory.get(
+ 'parameters', ''))
+ validationFail = XML.SubElement(params, 'validationFail')
+ validationFailValue = str(factory.get(
+ 'validation-fail', 'FAIL'))
+ if validationFailValue not in supported_actions:
+ raise JenkinsJobsException(
+ "validation-fail action must be one of %s" %
+ ", ".join(supported_actions))
+ validationFail.text = validationFailValue
+
projects = XML.SubElement(tconfig, 'projects')
projects.text = project_def['project']
condition = XML.SubElement(tconfig, 'condition')
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.xml b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.xml
new file mode 100644
index 000000000..278801a4b
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+ filename
+ propfile*.txt
+ FAIL
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.yaml b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.yaml
new file mode 100644
index 000000000..81b3a35c7
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile-optionals.yaml
@@ -0,0 +1,9 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: binaryfile
+ parameter-name: filename
+ file-pattern: propfile*.txt
+ no-files-found-action: FAIL
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.xml b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.xml
new file mode 100644
index 000000000..8858373bc
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+ filename
+ propfile*.txt
+ SKIP
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.yaml b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.yaml
new file mode 100644
index 000000000..a1efd0d2f
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-binaryfile.yaml
@@ -0,0 +1,8 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: binaryfile
+ parameter-name: filename
+ file-pattern: propfile*.txt
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.xml b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.xml
new file mode 100644
index 000000000..985d15dc4
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+ 0
+ 5
+ 1
+ EXAMPLE=NICE
+HELLO=WORLD
+
+ SKIP
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.yaml b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.yaml
new file mode 100644
index 000000000..871df9ace
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild-optionals.yaml
@@ -0,0 +1,13 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: counterbuild
+ from: 0
+ to: 5
+ step: 1
+ validation-fail: SKIP
+ parameters: |
+ EXAMPLE=NICE
+ HELLO=WORLD
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.xml b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.xml
new file mode 100644
index 000000000..07ffe060f
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+ 0
+ 5
+ 1
+
+ FAIL
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.yaml b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.yaml
new file mode 100644
index 000000000..ab885ef4f
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-counterbuild.yaml
@@ -0,0 +1,9 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: counterbuild
+ from: 0
+ to: 5
+ step: 1
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.xml b/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.xml
new file mode 100644
index 000000000..b089e1951
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+ propfile*.txt
+ NOPARMS
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.yaml b/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.yaml
new file mode 100644
index 000000000..09286d248
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-filebuild-optionals.yaml
@@ -0,0 +1,8 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: filebuild
+ file-pattern: propfile*.txt
+ no-files-found-action: NOPARMS
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-filebuild.xml b/tests/builders/fixtures/trigger-builds-configfactory-filebuild.xml
new file mode 100644
index 000000000..5fe8083c1
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-filebuild.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+ propfile*.txt
+ SKIP
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-filebuild.yaml b/tests/builders/fixtures/trigger-builds-configfactory-filebuild.yaml
new file mode 100644
index 000000000..738ec4c41
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-filebuild.yaml
@@ -0,0 +1,7 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ parameter-factories:
+ - factory: filebuild
+ file-pattern: propfile*.txt
+ block: true
\ No newline at end of file
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-multi.xml b/tests/builders/fixtures/trigger-builds-configfactory-multi.xml
new file mode 100644
index 000000000..8c35c4806
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-multi.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+ FOO="bar"
+
+
+
+
+ propfile*.txt
+ SKIP
+
+
+ filename
+ otherpropfile*.txt
+ SKIP
+
+
+ 0
+ 5
+ 1
+
+ FAIL
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds-configfactory-multi.yaml b/tests/builders/fixtures/trigger-builds-configfactory-multi.yaml
new file mode 100644
index 000000000..96b047828
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds-configfactory-multi.yaml
@@ -0,0 +1,18 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ predefined-parameters:
+ FOO="bar"
+ current-parameters: true
+ svn-revision: true
+ parameter-factories:
+ - factory: filebuild
+ file-pattern: propfile*.txt
+ - factory: binaryfile
+ parameter-name: filename
+ file-pattern: otherpropfile*.txt
+ - factory: counterbuild
+ from: 0
+ to: 5
+ step: 1
+ block: true
diff --git a/tests/builders/fixtures/trigger-builds004.xml b/tests/builders/fixtures/trigger-builds004.xml
new file mode 100644
index 000000000..0e23bab5e
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds004.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+ propfile.txt
+ false
+
+
+ build_started
+ ALWAYS
+ false
+ false
+
+
+ FAILURE
+ 2
+ RED
+
+
+ UNSTABLE
+ 1
+ YELLOW
+
+
+ FAILURE
+ 2
+ RED
+
+
+
+
+
+
+
diff --git a/tests/builders/fixtures/trigger-builds004.yaml b/tests/builders/fixtures/trigger-builds004.yaml
new file mode 100644
index 000000000..d9da643ba
--- /dev/null
+++ b/tests/builders/fixtures/trigger-builds004.yaml
@@ -0,0 +1,6 @@
+builders:
+ - trigger-builds:
+ - project: "build_started"
+ property-file: propfile.txt
+ property-file-fail-on-missing: false
+ block: true