Merge "Update ScriptTrigger plugin"
This commit is contained in:
commit
bc449aea10
@ -40,6 +40,7 @@ from jenkins_jobs.errors import JenkinsJobsException
|
|||||||
from jenkins_jobs.errors import MissingAttributeError
|
from jenkins_jobs.errors import MissingAttributeError
|
||||||
import jenkins_jobs.modules.base
|
import jenkins_jobs.modules.base
|
||||||
from jenkins_jobs.modules import hudson_model
|
from jenkins_jobs.modules import hudson_model
|
||||||
|
from jenkins_jobs.modules.helpers import convert_mapping_to_xml
|
||||||
|
|
||||||
logger = logging.getLogger(str(__name__))
|
logger = logging.getLogger(str(__name__))
|
||||||
|
|
||||||
@ -1493,35 +1494,41 @@ def script(parser, xml_parent, data):
|
|||||||
|
|
||||||
:arg str label: Restrict where the polling should run. (default '')
|
:arg str label: Restrict where the polling should run. (default '')
|
||||||
:arg str script: A shell or batch script. (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 str cron: cron syntax of when to run (default '')
|
||||||
:arg bool enable-concurrent: Enables triggering concurrent builds.
|
:arg bool enable-concurrent: Enables triggering concurrent builds.
|
||||||
(default false)
|
(default false)
|
||||||
:arg int exit-code: If the exit code of the script execution returns this
|
:arg int exit-code: If the exit code of the script execution returns this
|
||||||
expected exit code, a build is scheduled. (default 0)
|
expected exit code, a build is scheduled. (default 0)
|
||||||
|
|
||||||
Example:
|
Full Example:
|
||||||
|
|
||||||
.. literalinclude:: /../../tests/triggers/fixtures/script001.yaml
|
.. literalinclude:: /../../tests/triggers/fixtures/script-full.yaml
|
||||||
|
:language: yaml
|
||||||
|
|
||||||
|
Minimal Example:
|
||||||
|
|
||||||
|
.. literalinclude:: /../../tests/triggers/fixtures/script-minimal.yaml
|
||||||
|
:language: yaml
|
||||||
"""
|
"""
|
||||||
data = data if data else {}
|
|
||||||
st = XML.SubElement(
|
st = XML.SubElement(
|
||||||
xml_parent,
|
xml_parent,
|
||||||
'org.jenkinsci.plugins.scripttrigger.ScriptTrigger'
|
'org.jenkinsci.plugins.scripttrigger.ScriptTrigger'
|
||||||
)
|
)
|
||||||
|
st.set('plugin', 'scripttrigger')
|
||||||
label = data.get('label')
|
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()
|
XML.SubElement(st, 'labelRestriction').text = str(bool(label)).lower()
|
||||||
if label:
|
if label:
|
||||||
XML.SubElement(st, 'triggerLabel').text = 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):
|
def groovy_script(parser, xml_parent, data):
|
||||||
@ -1538,35 +1545,42 @@ def groovy_script(parser, xml_parent, data):
|
|||||||
evaluated to true, a build is scheduled. (default '')
|
evaluated to true, a build is scheduled. (default '')
|
||||||
:arg str script-file-path: Groovy script path. (default '')
|
:arg str script-file-path: Groovy script path. (default '')
|
||||||
:arg str property-file-path: Property file path. All properties will be set
|
: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 bool enable-concurrent: Enable concurrent build. (default false)
|
||||||
:arg str label: Restrict where the polling should run. (default '')
|
:arg str label: Restrict where the polling should run. (default '')
|
||||||
:arg str cron: cron syntax of when to 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(
|
gst = XML.SubElement(
|
||||||
xml_parent,
|
xml_parent,
|
||||||
'org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger'
|
'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')
|
label = data.get('label')
|
||||||
XML.SubElement(gst, 'labelRestriction').text = str(bool(label)).lower()
|
XML.SubElement(gst, 'labelRestriction').text = str(bool(label)).lower()
|
||||||
if label:
|
if label:
|
||||||
XML.SubElement(gst, 'triggerLabel').text = label
|
XML.SubElement(gst, 'triggerLabel').text = label
|
||||||
XML.SubElement(gst, 'spec').text = str(data.get('cron', ''))
|
|
||||||
|
|
||||||
|
|
||||||
def rabbitmq(parser, xml_parent, data):
|
def rabbitmq(parser, xml_parent, data):
|
||||||
|
15
tests/triggers/fixtures/groovy-script-full.xml
Normal file
15
tests/triggers/fixtures/groovy-script-full.xml
Normal file
@ -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>
|
9
tests/triggers/fixtures/groovy-script-full.yaml
Normal file
9
tests/triggers/fixtures/groovy-script-full.yaml
Normal file
@ -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
|
14
tests/triggers/fixtures/groovy-script-minimal.xml
Normal file
14
tests/triggers/fixtures/groovy-script-minimal.xml
Normal file
@ -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>
|
2
tests/triggers/fixtures/groovy-script-minimal.yaml
Normal file
2
tests/triggers/fixtures/groovy-script-minimal.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
triggers:
|
||||||
|
- groovy-script
|
@ -1,14 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<triggers class="vector">
|
<triggers class="vector">
|
||||||
<org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
|
<org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger plugin="scripttrigger">
|
||||||
<groovySystemScript>true</groovySystemScript>
|
<groovySystemScript>true</groovySystemScript>
|
||||||
<groovyExpression/>
|
<groovyExpression/>
|
||||||
<groovyFilePath>path/to/filename</groovyFilePath>
|
<groovyFilePath>path/to/filename</groovyFilePath>
|
||||||
|
<propertiesFilePath/>
|
||||||
<enableConcurrentBuild>true</enableConcurrentBuild>
|
<enableConcurrentBuild>true</enableConcurrentBuild>
|
||||||
|
<spec>H/15 * * * *</spec>
|
||||||
<labelRestriction>true</labelRestriction>
|
<labelRestriction>true</labelRestriction>
|
||||||
<triggerLabel>master</triggerLabel>
|
<triggerLabel>master</triggerLabel>
|
||||||
<spec>H/15 * * * *</spec>
|
|
||||||
</org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
|
</org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger>
|
||||||
</triggers>
|
</triggers>
|
||||||
</project>
|
</project>
|
@ -5,4 +5,3 @@ triggers:
|
|||||||
enable-concurrent: true
|
enable-concurrent: true
|
||||||
label: master
|
label: master
|
||||||
system-script: true
|
system-script: true
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<triggers class="vector">
|
<triggers class="vector">
|
||||||
<org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
<org.jenkinsci.plugins.scripttrigger.ScriptTrigger plugin="scripttrigger">
|
||||||
<script>exit 0</script>
|
<script>exit 0</script>
|
||||||
<scriptFilePath>$WORKSPACE/scripts</scriptFilePath>
|
<scriptFilePath>$WORKSPACE/scripts</scriptFilePath>
|
||||||
<spec>H/15 * * * *</spec>
|
<spec>H/15 * * * *</spec>
|
||||||
|
<enableConcurrentBuild>true</enableConcurrentBuild>
|
||||||
|
<exitCode>0</exitCode>
|
||||||
<labelRestriction>true</labelRestriction>
|
<labelRestriction>true</labelRestriction>
|
||||||
<triggerLabel>master</triggerLabel>
|
<triggerLabel>master</triggerLabel>
|
||||||
<enableConcurrentBuild>false</enableConcurrentBuild>
|
|
||||||
<exitCode>0</exitCode>
|
|
||||||
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
||||||
</triggers>
|
</triggers>
|
||||||
</project>
|
</project>
|
@ -3,7 +3,7 @@ triggers:
|
|||||||
script: 'exit 0'
|
script: 'exit 0'
|
||||||
script-file-path: '$WORKSPACE/scripts'
|
script-file-path: '$WORKSPACE/scripts'
|
||||||
cron: 'H/15 * * * *'
|
cron: 'H/15 * * * *'
|
||||||
enable-concurrent: False
|
enable-concurrent: true
|
||||||
label: master
|
label: master
|
||||||
exit-code: 0
|
exit-code: 0
|
||||||
|
|
13
tests/triggers/fixtures/script-minimal.xml
Normal file
13
tests/triggers/fixtures/script-minimal.xml
Normal file
@ -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>
|
2
tests/triggers/fixtures/script-minimal.yaml
Normal file
2
tests/triggers/fixtures/script-minimal.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
triggers:
|
||||||
|
- script
|
@ -1,13 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<triggers class="vector">
|
<triggers class="vector">
|
||||||
<org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
<org.jenkinsci.plugins.scripttrigger.ScriptTrigger plugin="scripttrigger">
|
||||||
<script>exit 0</script>
|
<script>exit 0</script>
|
||||||
|
<scriptFilePath/>
|
||||||
<spec>H/15 * * * *</spec>
|
<spec>H/15 * * * *</spec>
|
||||||
<labelRestriction>true</labelRestriction>
|
|
||||||
<triggerLabel>master</triggerLabel>
|
|
||||||
<enableConcurrentBuild>false</enableConcurrentBuild>
|
<enableConcurrentBuild>false</enableConcurrentBuild>
|
||||||
<exitCode>0</exitCode>
|
<exitCode>0</exitCode>
|
||||||
|
<labelRestriction>true</labelRestriction>
|
||||||
|
<triggerLabel>master</triggerLabel>
|
||||||
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
</org.jenkinsci.plugins.scripttrigger.ScriptTrigger>
|
||||||
</triggers>
|
</triggers>
|
||||||
</project>
|
</project>
|
||||||
|
Loading…
Reference in New Issue
Block a user