Add support for builder Groovy and System Groovy
Closes-Bug: #1251869 Change-Id: Ibc49e1aca7b33eb9c0c21472a924cb375069ee51
This commit is contained in:
parent
e1ddd23483
commit
04139e0f5e
@ -494,6 +494,104 @@ def gradle(parser, xml_parent, data):
|
||||
'use-root-dir', False)).lower()
|
||||
|
||||
|
||||
def _groovy_common_scriptSource(data):
|
||||
"""Helper function to generate the XML element common to groovy builders
|
||||
"""
|
||||
|
||||
scriptSource = XML.Element("scriptSource")
|
||||
if 'command' in data and 'file' in data:
|
||||
raise JenkinsJobsException("Use just one of 'command' or 'file'")
|
||||
|
||||
if 'command' in data:
|
||||
command = XML.SubElement(scriptSource, 'command')
|
||||
command.text = str(data['command'])
|
||||
scriptSource.set('class', 'hudson.plugins.groovy.StringScriptSource')
|
||||
elif 'file' in data:
|
||||
scriptFile = XML.SubElement(scriptSource, 'scriptFile')
|
||||
scriptFile.text = str(data['file'])
|
||||
scriptSource.set('class', 'hudson.plugins.groovy.FileScriptSource')
|
||||
else:
|
||||
raise JenkinsJobsException("A groovy command or file is required")
|
||||
|
||||
return scriptSource
|
||||
|
||||
|
||||
def groovy(parser, xml_parent, data):
|
||||
"""yaml: groovy
|
||||
Execute a groovy script or command.
|
||||
Requires the Jenkins `Groovy Plugin
|
||||
<https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin>`_
|
||||
|
||||
:arg str file: Groovy file to run.
|
||||
(Alternative: you can chose a command instead)
|
||||
:arg str command: Groovy command to run.
|
||||
(Alternative: you can chose a script file instead)
|
||||
:arg str version: Groovy version to use. (default '(Default)')
|
||||
:arg str parameters: Parameters for the Groovy executable. (optional)
|
||||
:arg str script-parameters: These parameters will be passed to the script.
|
||||
(optional)
|
||||
:arg str properties: Instead of passing properties using the -D parameter
|
||||
you can define them here. (optional)
|
||||
:arg str java-opts: Direct access to JAVA_OPTS. Properties allows only
|
||||
-D properties, while sometimes also other properties like -XX need to
|
||||
be setup. It can be done here. This line is appended at the end of
|
||||
JAVA_OPTS string. (optional)
|
||||
:arg str class-path: Specify script classpath here. Each line is one
|
||||
class path item. (optional)
|
||||
|
||||
Examples:
|
||||
|
||||
.. literalinclude:: ../../tests/builders/fixtures/groovy001.yaml
|
||||
:language: yaml
|
||||
.. literalinclude:: ../../tests/builders/fixtures/groovy002.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
|
||||
root_tag = 'hudson.plugins.groovy.Groovy'
|
||||
groovy = XML.SubElement(xml_parent, root_tag)
|
||||
|
||||
groovy.append(_groovy_common_scriptSource(data))
|
||||
XML.SubElement(groovy, 'groovyName').text = \
|
||||
str(data.get('version', "(Default)"))
|
||||
XML.SubElement(groovy, 'parameters').text = str(data.get('parameters', ""))
|
||||
XML.SubElement(groovy, 'scriptParameters').text = \
|
||||
str(data.get('script-parameters', ""))
|
||||
XML.SubElement(groovy, 'properties').text = str(data.get('properties', ""))
|
||||
XML.SubElement(groovy, 'javaOpts').text = str(data.get('java-opts', ""))
|
||||
XML.SubElement(groovy, 'classPath').text = str(data.get('class-path', ""))
|
||||
|
||||
|
||||
def system_groovy(parser, xml_parent, data):
|
||||
"""yaml: system-groovy
|
||||
Execute a system groovy script or command.
|
||||
Requires the Jenkins `Groovy Plugin
|
||||
<https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin>`_
|
||||
|
||||
:arg str file: Groovy file to run.
|
||||
(Alternative: you can chose a command instead)
|
||||
:arg str command: Groovy command to run.
|
||||
(Alternative: you can chose a script file instead)
|
||||
:arg str bindings: Define variable bindings (in the properties file
|
||||
format). Specified variables can be addressed from the script. (optional)
|
||||
:arg str class-path: Specify script classpath here. Each line is one class
|
||||
path item. (optional)
|
||||
|
||||
Examples:
|
||||
|
||||
.. literalinclude:: ../../tests/builders/fixtures/system-groovy001.yaml
|
||||
:language: yaml
|
||||
.. literalinclude:: ../../tests/builders/fixtures/system-groovy002.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
|
||||
root_tag = 'hudson.plugins.groovy.SystemGroovy'
|
||||
sysgroovy = XML.SubElement(xml_parent, root_tag)
|
||||
sysgroovy.append(_groovy_common_scriptSource(data))
|
||||
XML.SubElement(sysgroovy, 'bindings').text = str(data.get('bindings', ""))
|
||||
XML.SubElement(sysgroovy, 'classpath').text = \
|
||||
str(data.get('class-path', ""))
|
||||
|
||||
|
||||
def batch(parser, xml_parent, data):
|
||||
"""yaml: batch
|
||||
Execute a batch command.
|
||||
|
@ -50,6 +50,7 @@ jenkins_jobs.builders =
|
||||
critical-block-end=jenkins_jobs.modules.builders:critical_block_end
|
||||
gradle=jenkins_jobs.modules.builders:gradle
|
||||
grails=jenkins_jobs.modules.builders:grails
|
||||
groovy=jenkins_jobs.modules.builders:groovy
|
||||
inject=jenkins_jobs.modules.builders:inject
|
||||
maven-target=jenkins_jobs.modules.builders:maven_target
|
||||
msbuild=jenkins_jobs.modules.builders:msbuild
|
||||
@ -58,6 +59,7 @@ jenkins_jobs.builders =
|
||||
sbt=jenkins_jobs.modules.builders:sbt
|
||||
shell=jenkins_jobs.modules.builders:shell
|
||||
shining-panda=jenkins_jobs.modules.builders:shining_panda
|
||||
system-groovy=jenkins_jobs.modules.builders:system_groovy
|
||||
trigger-builds=jenkins_jobs.modules.builders:trigger_builds
|
||||
jenkins_jobs.reporters =
|
||||
email=jenkins_jobs.modules.reporters:email
|
||||
|
16
tests/builders/fixtures/groovy001.xml
Normal file
16
tests/builders/fixtures/groovy001.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<hudson.plugins.groovy.Groovy>
|
||||
<scriptSource class="hudson.plugins.groovy.FileScriptSource">
|
||||
<scriptFile>test.groovy</scriptFile>
|
||||
</scriptSource>
|
||||
<groovyName>(Default)</groovyName>
|
||||
<parameters/>
|
||||
<scriptParameters/>
|
||||
<properties/>
|
||||
<javaOpts/>
|
||||
<classPath/>
|
||||
</hudson.plugins.groovy.Groovy>
|
||||
</builders>
|
||||
</project>
|
3
tests/builders/fixtures/groovy001.yaml
Normal file
3
tests/builders/fixtures/groovy001.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
builders:
|
||||
- groovy:
|
||||
file: "test.groovy"
|
16
tests/builders/fixtures/groovy002.xml
Normal file
16
tests/builders/fixtures/groovy002.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<hudson.plugins.groovy.Groovy>
|
||||
<scriptSource class="hudson.plugins.groovy.StringScriptSource">
|
||||
<command>Some command</command>
|
||||
</scriptSource>
|
||||
<groovyName>Groovy 1.2</groovyName>
|
||||
<parameters>parameters</parameters>
|
||||
<scriptParameters>script parameters</scriptParameters>
|
||||
<properties>properties</properties>
|
||||
<javaOpts>java opts</javaOpts>
|
||||
<classPath/>
|
||||
</hudson.plugins.groovy.Groovy>
|
||||
</builders>
|
||||
</project>
|
8
tests/builders/fixtures/groovy002.yaml
Normal file
8
tests/builders/fixtures/groovy002.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
builders:
|
||||
- groovy:
|
||||
command: "Some command"
|
||||
version: "Groovy 1.2"
|
||||
parameters: "parameters"
|
||||
script-parameters: "script parameters"
|
||||
properties: "properties"
|
||||
java-opts: "java opts"
|
12
tests/builders/fixtures/system-groovy001.xml
Normal file
12
tests/builders/fixtures/system-groovy001.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<hudson.plugins.groovy.SystemGroovy>
|
||||
<scriptSource class="hudson.plugins.groovy.FileScriptSource">
|
||||
<scriptFile>test.groovy</scriptFile>
|
||||
</scriptSource>
|
||||
<bindings/>
|
||||
<classpath/>
|
||||
</hudson.plugins.groovy.SystemGroovy>
|
||||
</builders>
|
||||
</project>
|
3
tests/builders/fixtures/system-groovy001.yaml
Normal file
3
tests/builders/fixtures/system-groovy001.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
builders:
|
||||
- system-groovy:
|
||||
file: "test.groovy"
|
12
tests/builders/fixtures/system-groovy002.xml
Normal file
12
tests/builders/fixtures/system-groovy002.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<hudson.plugins.groovy.SystemGroovy>
|
||||
<scriptSource class="hudson.plugins.groovy.StringScriptSource">
|
||||
<command>Some command</command>
|
||||
</scriptSource>
|
||||
<bindings>Some bindings</bindings>
|
||||
<classpath>Some classpath</classpath>
|
||||
</hudson.plugins.groovy.SystemGroovy>
|
||||
</builders>
|
||||
</project>
|
5
tests/builders/fixtures/system-groovy002.yaml
Normal file
5
tests/builders/fixtures/system-groovy002.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
builders:
|
||||
- system-groovy:
|
||||
command: "Some command"
|
||||
bindings: "Some bindings"
|
||||
class-path: "Some classpath"
|
Loading…
Reference in New Issue
Block a user