summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Cravo <joaogbcravo@gmail.com>2014-05-26 18:18:12 +0100
committerJoão Cravo <joaogbcravo@gmail.com>2014-07-07 17:39:07 +0100
commit04139e0f5e8f25d974526b619783eb1dfd3d83f3 (patch)
treef2be8980630071fc3b2f2d8fbc15563c94a782a4
parente1ddd234832a31c7feb25fd18d49dbf2d91f326e (diff)
downloadpython-jenkins-job-builder-04139e0f5e8f25d974526b619783eb1dfd3d83f3.tar.gz
python-jenkins-job-builder-04139e0f5e8f25d974526b619783eb1dfd3d83f3.tar.xz
python-jenkins-job-builder-04139e0f5e8f25d974526b619783eb1dfd3d83f3.zip
Add support for builder Groovy and System Groovy
Closes-Bug: #1251869 Change-Id: Ibc49e1aca7b33eb9c0c21472a924cb375069ee51
-rw-r--r--jenkins_jobs/modules/builders.py98
-rw-r--r--setup.cfg2
-rw-r--r--tests/builders/fixtures/groovy001.xml16
-rw-r--r--tests/builders/fixtures/groovy001.yaml3
-rw-r--r--tests/builders/fixtures/groovy002.xml16
-rw-r--r--tests/builders/fixtures/groovy002.yaml8
-rw-r--r--tests/builders/fixtures/system-groovy001.xml12
-rw-r--r--tests/builders/fixtures/system-groovy001.yaml3
-rw-r--r--tests/builders/fixtures/system-groovy002.xml12
-rw-r--r--tests/builders/fixtures/system-groovy002.yaml5
10 files changed, 175 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py
index e7b3a8b5..dd58eddf 100644
--- a/jenkins_jobs/modules/builders.py
+++ b/jenkins_jobs/modules/builders.py
@@ -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.
diff --git a/setup.cfg b/setup.cfg
index 6bda4b43..ad44d6f9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/tests/builders/fixtures/groovy001.xml b/tests/builders/fixtures/groovy001.xml
new file mode 100644
index 00000000..6682fa3e
--- /dev/null
+++ b/tests/builders/fixtures/groovy001.xml
@@ -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>
diff --git a/tests/builders/fixtures/groovy001.yaml b/tests/builders/fixtures/groovy001.yaml
new file mode 100644
index 00000000..e12716e2
--- /dev/null
+++ b/tests/builders/fixtures/groovy001.yaml
@@ -0,0 +1,3 @@
+builders:
+ - groovy:
+ file: "test.groovy"
diff --git a/tests/builders/fixtures/groovy002.xml b/tests/builders/fixtures/groovy002.xml
new file mode 100644
index 00000000..dae670e2
--- /dev/null
+++ b/tests/builders/fixtures/groovy002.xml
@@ -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>
diff --git a/tests/builders/fixtures/groovy002.yaml b/tests/builders/fixtures/groovy002.yaml
new file mode 100644
index 00000000..30c7be24
--- /dev/null
+++ b/tests/builders/fixtures/groovy002.yaml
@@ -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"
diff --git a/tests/builders/fixtures/system-groovy001.xml b/tests/builders/fixtures/system-groovy001.xml
new file mode 100644
index 00000000..23bde23b
--- /dev/null
+++ b/tests/builders/fixtures/system-groovy001.xml
@@ -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>
diff --git a/tests/builders/fixtures/system-groovy001.yaml b/tests/builders/fixtures/system-groovy001.yaml
new file mode 100644
index 00000000..553f69bd
--- /dev/null
+++ b/tests/builders/fixtures/system-groovy001.yaml
@@ -0,0 +1,3 @@
+builders:
+ - system-groovy:
+ file: "test.groovy"
diff --git a/tests/builders/fixtures/system-groovy002.xml b/tests/builders/fixtures/system-groovy002.xml
new file mode 100644
index 00000000..d1e89fa3
--- /dev/null
+++ b/tests/builders/fixtures/system-groovy002.xml
@@ -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>
diff --git a/tests/builders/fixtures/system-groovy002.yaml b/tests/builders/fixtures/system-groovy002.yaml
new file mode 100644
index 00000000..969e429e
--- /dev/null
+++ b/tests/builders/fixtures/system-groovy002.yaml
@@ -0,0 +1,5 @@
+builders:
+ - system-groovy:
+ command: "Some command"
+ bindings: "Some bindings"
+ class-path: "Some classpath"