publishers: groovy-postbuild changes between 1.x & 2.x
This patch hides differences between versions of this plugin. From version 2.0, Groovy Postbuild plugin introduces Script Security Plugin. It adds new options and also it changes xml structure. You can find all details on home page in "Migration from 1.x" section: https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin Change-Id: Ica4ef3132f9ea56f57ec3cf1590021750bfea594 Signed-off-by: Lukas Bednar <lbednar@redhat.com> Closes-bug: #1392360
This commit is contained in:
parent
0f4858186e
commit
ccfe2daf8a
@ -34,6 +34,7 @@ from jenkins_jobs.errors import JenkinsJobsException
|
||||
import logging
|
||||
import pkg_resources
|
||||
import sys
|
||||
import six
|
||||
import random
|
||||
|
||||
|
||||
@ -1687,7 +1688,21 @@ def groovy_postbuild(parser, xml_parent, data):
|
||||
Requires the Jenkins :jenkins-wiki:`Groovy Postbuild Plugin
|
||||
<Groovy+Postbuild+Plugin>`.
|
||||
|
||||
:Parameter: the groovy script to execute
|
||||
Please pay attention on version of plugin you have installed.
|
||||
There were incompatible changes between 1.x and 2.x. Please see
|
||||
:jenkins-wiki:`home page <Groovy+Postbuild+Plugin>` of this plugin
|
||||
for full information including migration process.
|
||||
|
||||
:arg str script: The groovy script to execute
|
||||
:arg list classpath: List of additional classpaths (>=1.6)
|
||||
:arg str on-failure: In case of script failure leave build as it is
|
||||
for "nothing" option, mark build as unstable
|
||||
for "unstable" and mark job as failure for "failed"
|
||||
(default is "nothing")
|
||||
:arg bool matrix-parent: Run script for matrix parent only (>=1.9)
|
||||
(default false)
|
||||
:arg bool sandbox: Execute script inside of groovy sandbox (>=2.0)
|
||||
(default false)
|
||||
|
||||
Example:
|
||||
|
||||
@ -1695,10 +1710,65 @@ def groovy_postbuild(parser, xml_parent, data):
|
||||
/../../tests/publishers/fixtures/groovy-postbuild001.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
root_tag = 'org.jvnet.hudson.plugins.groovypostbuild.'\
|
||||
'GroovyPostbuildRecorder'
|
||||
logger = logging.getLogger("%s:groovy-postbuild" % __name__)
|
||||
# Backward compatibility with old format
|
||||
if isinstance(data, six.string_types):
|
||||
logger.warn(
|
||||
"You use depricated configuration, please follow documentation "
|
||||
"to change configuration. It is not going to be supported in "
|
||||
"future releases!"
|
||||
)
|
||||
data = {
|
||||
'script': data,
|
||||
}
|
||||
# There are incompatible changes, we need to know version
|
||||
info = parser.registry.get_plugin_info('groovy-postbuild')
|
||||
version = pkg_resources.parse_version(info.get('version', "0"))
|
||||
# Version specific predicates
|
||||
matrix_parent_support = version >= pkg_resources.parse_version("1.9")
|
||||
security_plugin_support = version >= pkg_resources.parse_version("2.0")
|
||||
extra_classpath_support = version >= pkg_resources.parse_version("1.6")
|
||||
|
||||
root_tag = (
|
||||
'org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder'
|
||||
)
|
||||
groovy = XML.SubElement(xml_parent, root_tag)
|
||||
XML.SubElement(groovy, 'groovyScript').text = data
|
||||
|
||||
behavior = data.get('on-failure')
|
||||
XML.SubElement(groovy, 'behavior').text = {
|
||||
'unstable': '1',
|
||||
'failed': '2',
|
||||
}.get(behavior, '0')
|
||||
|
||||
if matrix_parent_support:
|
||||
XML.SubElement(
|
||||
groovy,
|
||||
'runForMatrixParent',
|
||||
).text = str(data.get('matrix-parent', False)).lower()
|
||||
|
||||
classpaths = data.get('classpath', list())
|
||||
if security_plugin_support:
|
||||
script = XML.SubElement(groovy, 'script')
|
||||
XML.SubElement(script, 'script').text = data.get('script')
|
||||
XML.SubElement(script, 'sandbox').text = str(
|
||||
data.get('sandbox', False)
|
||||
).lower()
|
||||
if classpaths:
|
||||
classpath = XML.SubElement(script, 'classpath')
|
||||
for path in classpaths:
|
||||
script_path = XML.SubElement(classpath, 'entry')
|
||||
XML.SubElement(script_path, 'url').text = path
|
||||
else:
|
||||
XML.SubElement(groovy, 'groovyScript').text = data.get('script')
|
||||
if extra_classpath_support and classpaths:
|
||||
classpath = XML.SubElement(groovy, 'classpath')
|
||||
for path in classpaths:
|
||||
script_path = XML.SubElement(
|
||||
classpath,
|
||||
'org.jvnet.hudson.plugins.groovypostbuild.'
|
||||
'GroovyScriptPath',
|
||||
)
|
||||
XML.SubElement(script_path, 'path').text = path
|
||||
|
||||
|
||||
def base_publish_over(xml_parent, data, console_prefix,
|
||||
|
9
tests/publishers/fixtures/groovy-postbuild000.xml
Normal file
9
tests/publishers/fixtures/groovy-postbuild000.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
<behavior>1</behavior>
|
||||
<groovyScript>manager.buildFailure()</groovyScript>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
</publishers>
|
||||
</project>
|
8
tests/publishers/fixtures/groovy-postbuild000.yaml
Normal file
8
tests/publishers/fixtures/groovy-postbuild000.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
publishers:
|
||||
- groovy-postbuild:
|
||||
script: "manager.buildFailure()"
|
||||
classpath:
|
||||
- "file:///path/to/your/lib"
|
||||
- "file:///path/to/your/lib"
|
||||
on-failure: "unstable"
|
||||
matrix-parent: true
|
@ -0,0 +1,3 @@
|
||||
- longName: 'Groovy Postbuild'
|
||||
shortName: 'groovy-postbuild'
|
||||
version: "2.0"
|
@ -2,7 +2,20 @@
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
<groovyScript>manager.buildFailure()</groovyScript>
|
||||
<behavior>2</behavior>
|
||||
<runForMatrixParent>true</runForMatrixParent>
|
||||
<script>
|
||||
<script>manager.buildFailure()</script>
|
||||
<sandbox>false</sandbox>
|
||||
<classpath>
|
||||
<entry>
|
||||
<url>file:///path/to/your/lib</url>
|
||||
</entry>
|
||||
<entry>
|
||||
<url>file:///path/to/your/lib</url>
|
||||
</entry>
|
||||
</classpath>
|
||||
</script>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
</publishers>
|
||||
</project>
|
||||
|
@ -1,2 +1,8 @@
|
||||
publishers:
|
||||
- groovy-postbuild: "manager.buildFailure()"
|
||||
- groovy-postbuild:
|
||||
script: "manager.buildFailure()"
|
||||
classpath:
|
||||
- "file:///path/to/your/lib"
|
||||
- "file:///path/to/your/lib"
|
||||
on-failure: "failed"
|
||||
matrix-parent: true
|
||||
|
@ -0,0 +1,3 @@
|
||||
- longName: 'Groovy Postbuild'
|
||||
shortName: 'groovy-postbuild'
|
||||
version: "1.6"
|
17
tests/publishers/fixtures/groovy-postbuild002.xml
Normal file
17
tests/publishers/fixtures/groovy-postbuild002.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
<behavior>0</behavior>
|
||||
<groovyScript>manager.buildFailure()</groovyScript>
|
||||
<classpath>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<path>file:///path/to/your/lib</path>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<path>file:///path/to/your/lib</path>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
</classpath>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
</publishers>
|
||||
</project>
|
8
tests/publishers/fixtures/groovy-postbuild002.yaml
Normal file
8
tests/publishers/fixtures/groovy-postbuild002.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
publishers:
|
||||
- groovy-postbuild:
|
||||
script: "manager.buildFailure()"
|
||||
classpath:
|
||||
- "file:///path/to/your/lib"
|
||||
- "file:///path/to/your/lib"
|
||||
on-failure: "wrong_option"
|
||||
matrix-parent: true
|
@ -0,0 +1,3 @@
|
||||
- longName: 'Groovy Postbuild'
|
||||
shortName: 'groovy-postbuild'
|
||||
version: "1.9"
|
18
tests/publishers/fixtures/groovy-postbuild003.xml
Normal file
18
tests/publishers/fixtures/groovy-postbuild003.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
<behavior>0</behavior>
|
||||
<runForMatrixParent>false</runForMatrixParent>
|
||||
<groovyScript>manager.buildFailure()</groovyScript>
|
||||
<classpath>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<path>file:///path/to/your/lib</path>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
<path>file:///path/to/your/lib</path>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
||||
</classpath>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
</publishers>
|
||||
</project>
|
7
tests/publishers/fixtures/groovy-postbuild003.yaml
Normal file
7
tests/publishers/fixtures/groovy-postbuild003.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
publishers:
|
||||
- groovy-postbuild:
|
||||
script: "manager.buildFailure()"
|
||||
classpath:
|
||||
- "file:///path/to/your/lib"
|
||||
- "file:///path/to/your/lib"
|
||||
matrix-parent: false
|
9
tests/publishers/fixtures/groovy-postbuild004.xml
Normal file
9
tests/publishers/fixtures/groovy-postbuild004.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
<behavior>0</behavior>
|
||||
<groovyScript>manager.buildFailure()</groovyScript>
|
||||
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
||||
</publishers>
|
||||
</project>
|
2
tests/publishers/fixtures/groovy-postbuild004.yaml
Normal file
2
tests/publishers/fixtures/groovy-postbuild004.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
publishers:
|
||||
- groovy-postbuild: "manager.buildFailure()"
|
Loading…
x
Reference in New Issue
Block a user