summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKien Ha <kienha9922@gmail.com>2016-06-20 18:14:33 -0400
committerKien Ha <kienha9922@gmail.com>2016-07-01 11:21:06 -0400
commit7b8f989e40bec6327cb354bfb33493860993a455 (patch)
tree7b6caa614357e5006e4708be36a513690283be25
parentfda76531d96f604772baf81a872405aced937016 (diff)
downloadpython-jenkins-job-builder-7b8f989e40bec6327cb354bfb33493860993a455.tar.gz
python-jenkins-job-builder-7b8f989e40bec6327cb354bfb33493860993a455.tar.xz
python-jenkins-job-builder-7b8f989e40bec6327cb354bfb33493860993a455.zip
Update ScriptTrigger plugin
- Update to use convert_mapping_to_xml - Add minimal tests - Update docs Change-Id: I803de8b7f9195caac06fa393634c36d799179cc3 Signed-off-by: Kien Ha <kienha9922@gmail.com>
-rw-r--r--jenkins_jobs/modules/triggers.py66
-rw-r--r--tests/triggers/fixtures/groovy-script-full.xml15
-rw-r--r--tests/triggers/fixtures/groovy-script-full.yaml9
-rw-r--r--tests/triggers/fixtures/groovy-script-minimal.xml14
-rw-r--r--tests/triggers/fixtures/groovy-script-minimal.yaml2
-rw-r--r--tests/triggers/fixtures/groovy-script.xml7
-rw-r--r--tests/triggers/fixtures/groovy-script.yaml1
-rw-r--r--tests/triggers/fixtures/script-full.xml (renamed from tests/triggers/fixtures/script002.xml)6
-rw-r--r--tests/triggers/fixtures/script-full.yaml (renamed from tests/triggers/fixtures/script002.yaml)2
-rw-r--r--tests/triggers/fixtures/script-minimal.xml13
-rw-r--r--tests/triggers/fixtures/script-minimal.yaml2
-rw-r--r--tests/triggers/fixtures/script001.xml7
12 files changed, 107 insertions, 37 deletions
diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py
index 6c01416e..0da8eb6b 100644
--- a/jenkins_jobs/modules/triggers.py
+++ b/jenkins_jobs/modules/triggers.py
@@ -40,6 +40,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 convert_mapping_to_xml
logger = logging.getLogger(str(__name__))
@@ -1483,35 +1484,41 @@ def script(parser, xml_parent, data):
:arg str label: Restrict where the polling should run. (default '')
:arg str script: A shell or batch script. (default '')
- :arg str script-file-path: A shell or batch script path. (optional)
+ :arg str script-file-path: A shell or batch script path. (default '')
:arg str cron: cron syntax of when to run (default '')
:arg bool enable-concurrent: Enables triggering concurrent builds.
(default false)
:arg int exit-code: If the exit code of the script execution returns this
expected exit code, a build is scheduled. (default 0)
- Example:
+ Full Example:
+
+ .. literalinclude:: /../../tests/triggers/fixtures/script-full.yaml
+ :language: yaml
- .. literalinclude:: /../../tests/triggers/fixtures/script001.yaml
+ Minimal Example:
+
+ .. literalinclude:: /../../tests/triggers/fixtures/script-minimal.yaml
+ :language: yaml
"""
- data = data if data else {}
st = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.scripttrigger.ScriptTrigger'
)
+ st.set('plugin', 'scripttrigger')
label = data.get('label')
+ mappings = [
+ ('script', 'script', ''),
+ ('script-file-path', 'scriptFilePath', ''),
+ ('cron', 'spec', ''),
+ ('enable-concurrent', 'enableConcurrentBuild', False),
+ ('exit-code', 'exitCode', 0)
+ ]
+ convert_mapping_to_xml(st, data, mappings, fail_required=True)
- XML.SubElement(st, 'script').text = str(data.get('script', ''))
- if 'script-file-path' in data:
- XML.SubElement(st, 'scriptFilePath').text = str(
- data.get('script-file-path'))
- XML.SubElement(st, 'spec').text = str(data.get('cron', ''))
XML.SubElement(st, 'labelRestriction').text = str(bool(label)).lower()
if label:
XML.SubElement(st, 'triggerLabel').text = label
- XML.SubElement(st, 'enableConcurrentBuild').text = str(
- data.get('enable-concurrent', False)).lower()
- XML.SubElement(st, 'exitCode').text = str(data.get('exit-code', 0))
def groovy_script(parser, xml_parent, data):
@@ -1528,35 +1535,42 @@ def groovy_script(parser, xml_parent, data):
evaluated to true, a build is scheduled. (default '')
:arg str script-file-path: Groovy script path. (default '')
:arg str property-file-path: Property file path. All properties will be set
- as parameters for the triggered build. (optional)
+ as parameters for the triggered build. (default '')
:arg bool enable-concurrent: Enable concurrent build. (default false)
:arg str label: Restrict where the polling should run. (default '')
:arg str cron: cron syntax of when to run (default '')
- Example:
+ Full Example:
- .. literalinclude:: /../../tests/triggers/fixtures/groovy-script.yaml
+ .. literalinclude:: /../../tests/triggers/fixtures/groovy-script-full.yaml
+ :language: yaml
+
+ Minimal Example:
+
+ .. literalinclude::
+ /../../tests/triggers/fixtures/groovy-script-minimal.yaml
+ :language: yaml
"""
gst = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger'
)
+ gst.set('plugin', 'scripttrigger')
+
+ mappings = [
+ ('system-script', 'groovySystemScript', False),
+ ('script', 'groovyExpression', ''),
+ ('script-file-path', 'groovyFilePath', ''),
+ ('property-file-path', 'propertiesFilePath', ''),
+ ('enable-concurrent', 'enableConcurrentBuild', False),
+ ('cron', 'spec', ''),
+ ]
+ convert_mapping_to_xml(gst, data, mappings, fail_required=True)
- XML.SubElement(gst, 'groovySystemScript').text = str(
- data.get('system-script', False)).lower()
- XML.SubElement(gst, 'groovyExpression').text = str(data.get('script', ''))
- XML.SubElement(gst, 'groovyFilePath').text = str(data.get(
- 'script-file-path', ''))
- if 'property-file-path' in data:
- XML.SubElement(gst, 'propertiesFilePath').text = str(
- data.get('property-file-path'))
- XML.SubElement(gst, 'enableConcurrentBuild').text = str(
- data.get('enable-concurrent', False)).lower()
label = data.get('label')
XML.SubElement(gst, 'labelRestriction').text = str(bool(label)).lower()
if label:
XML.SubElement(gst, 'triggerLabel').text = label
- XML.SubElement(gst, 'spec').text = str(data.get('cron', ''))
def rabbitmq(parser, xml_parent, data):
diff --git a/tests/triggers/fixtures/groovy-script-full.xml b/tests/triggers/fixtures/groovy-script-full.xml
new file mode 100644
index 00000000..bb954311
--- /dev/null
+++ b/tests/triggers/fixtures/groovy-script-full.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <triggers class="vector">
+ <org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger plugin="scripttrigger">
+ <groovySystemScript>true</groovySystemScript>
+ <groovyExpression>groovy-content</groovyExpression>
+ <groovyFilePath>path/to/filename</groovyFilePath>
+ <propertiesFilePath>/path/to/properties/file</propertiesFilePath>
+ <enableConcurrentBuild>true</enableConcurrentBuild>
+ <spec>H/15 * * * *</spec>
+ <labelRestriction>true</labelRestriction>
+ <triggerLabel>master</triggerLabel>
+ </org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
+ </triggers>
+</project>
diff --git a/tests/triggers/fixtures/groovy-script-full.yaml b/tests/triggers/fixtures/groovy-script-full.yaml
new file mode 100644
index 00000000..c327e1c9
--- /dev/null
+++ b/tests/triggers/fixtures/groovy-script-full.yaml
@@ -0,0 +1,9 @@
+triggers:
+ - groovy-script:
+ script: groovy-content
+ script-file-path: path/to/filename
+ property-file-path: /path/to/properties/file
+ cron: H/15 * * * *
+ enable-concurrent: true
+ label: master
+ system-script: true
diff --git a/tests/triggers/fixtures/groovy-script-minimal.xml b/tests/triggers/fixtures/groovy-script-minimal.xml
new file mode 100644
index 00000000..92b9e684
--- /dev/null
+++ b/tests/triggers/fixtures/groovy-script-minimal.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <triggers class="vector">
+ <org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger plugin="scripttrigger">
+ <groovySystemScript>false</groovySystemScript>
+ <groovyExpression/>
+ <groovyFilePath/>
+ <propertiesFilePath/>
+ <enableConcurrentBuild>false</enableConcurrentBuild>
+ <spec/>
+ <labelRestriction>false</labelRestriction>
+ </org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
+ </triggers>
+</project>
diff --git a/tests/triggers/fixtures/groovy-script-minimal.yaml b/tests/triggers/fixtures/groovy-script-minimal.yaml
new file mode 100644
index 00000000..59c0fa6a
--- /dev/null
+++ b/tests/triggers/fixtures/groovy-script-minimal.yaml
@@ -0,0 +1,2 @@
+triggers:
+ - groovy-script
diff --git a/tests/triggers/fixtures/groovy-script.xml b/tests/triggers/fixtures/groovy-script.xml
index fa8ba54d..09c97d22 100644
--- a/tests/triggers/fixtures/groovy-script.xml
+++ b/tests/triggers/fixtures/groovy-script.xml
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
- <org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
+ <org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger plugin="scripttrigger">
<groovySystemScript>true</groovySystemScript>
<groovyExpression/>
<groovyFilePath>path/to/filename</groovyFilePath>
+ <propertiesFilePath/>
<enableConcurrentBuild>true</enableConcurrentBuild>
+ <spec>H/15 * * * *</spec>
<labelRestriction>true</labelRestriction>
<triggerLabel>master</triggerLabel>
- <spec>H/15 * * * *</spec>
</org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
</triggers>
-</project> \ No newline at end of file
+</project>
diff --git a/tests/triggers/fixtures/groovy-script.yaml b/tests/triggers/fixtures/groovy-script.yaml
index efd6a551..af496a39 100644
--- a/tests/triggers/fixtures/groovy-script.yaml
+++ b/tests/triggers/fixtures/groovy-script.yaml
@@ -5,4 +5,3 @@ triggers:
enable-concurrent: true
label: master
system-script: true
-
diff --git a/tests/triggers/fixtures/script002.xml b/tests/triggers/fixtures/script-full.xml
index 46e22bed..e486e678 100644
--- a/tests/triggers/fixtures/script002.xml
+++ b/tests/triggers/fixtures/script-full.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
- <org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
+ <org.jenkinsci.plugins.scripttrigger.ScriptTrigger plugin="scripttrigger">
<script>exit 0</script>
<scriptFilePath>$WORKSPACE/scripts</scriptFilePath>
<spec>H/15 * * * *</spec>
+ <enableConcurrentBuild>true</enableConcurrentBuild>
+ <exitCode>0</exitCode>
<labelRestriction>true</labelRestriction>
<triggerLabel>master</triggerLabel>
- <enableConcurrentBuild>false</enableConcurrentBuild>
- <exitCode>0</exitCode>
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
</triggers>
</project>
diff --git a/tests/triggers/fixtures/script002.yaml b/tests/triggers/fixtures/script-full.yaml
index 12b07297..f7739b00 100644
--- a/tests/triggers/fixtures/script002.yaml
+++ b/tests/triggers/fixtures/script-full.yaml
@@ -3,7 +3,7 @@ triggers:
script: 'exit 0'
script-file-path: '$WORKSPACE/scripts'
cron: 'H/15 * * * *'
- enable-concurrent: False
+ enable-concurrent: true
label: master
exit-code: 0
diff --git a/tests/triggers/fixtures/script-minimal.xml b/tests/triggers/fixtures/script-minimal.xml
new file mode 100644
index 00000000..dc0c5464
--- /dev/null
+++ b/tests/triggers/fixtures/script-minimal.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <triggers class="vector">
+ <org.jenkinsci.plugins.scripttrigger.ScriptTrigger plugin="scripttrigger">
+ <script/>
+ <scriptFilePath/>
+ <spec/>
+ <enableConcurrentBuild>false</enableConcurrentBuild>
+ <exitCode>0</exitCode>
+ <labelRestriction>false</labelRestriction>
+ </org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
+ </triggers>
+</project>
diff --git a/tests/triggers/fixtures/script-minimal.yaml b/tests/triggers/fixtures/script-minimal.yaml
new file mode 100644
index 00000000..fd42a534
--- /dev/null
+++ b/tests/triggers/fixtures/script-minimal.yaml
@@ -0,0 +1,2 @@
+triggers:
+ - script
diff --git a/tests/triggers/fixtures/script001.xml b/tests/triggers/fixtures/script001.xml
index 90926ad2..96e036af 100644
--- a/tests/triggers/fixtures/script001.xml
+++ b/tests/triggers/fixtures/script001.xml
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
- <org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
+ <org.jenkinsci.plugins.scripttrigger.ScriptTrigger plugin="scripttrigger">
<script>exit 0</script>
+ <scriptFilePath/>
<spec>H/15 * * * *</spec>
- <labelRestriction>true</labelRestriction>
- <triggerLabel>master</triggerLabel>
<enableConcurrentBuild>false</enableConcurrentBuild>
<exitCode>0</exitCode>
+ <labelRestriction>true</labelRestriction>
+ <triggerLabel>master</triggerLabel>
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
</triggers>
</project>