Added support for Exclusion plugin

This plugin allows the specification of critical blocks for builders.
Once a set of builders is "wrapped" by a critical block start/critical
block end pair, any resources (string) specified in the exclusion build
wrapper will cause any jobs with those same resources to block and allow
only one of those builds to proceed at a time.

Change-Id: I0bf4ab003709917aa7fe6ad57b31200f466658da
This commit is contained in:
Brad P. Crochet 2014-03-04 11:55:07 -05:00
parent 760873403b
commit 153fa6e2b1
15 changed files with 175 additions and 0 deletions

View File

@ -1048,6 +1048,64 @@ def sbt(parser, xml_parent, data):
'subdir-path', '')
def critical_block_start(parser, xml_parent, data):
"""yaml: critical-block-start
Designate the start of a critical block. Must be used in conjuction with
critical-block-end.
Must also add a build wrapper (exclusion), specifying the resources that
control the critical block. Otherwise, this will have no effect.
Requires Jenkins `Exclusion Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin>`_
Example::
wrappers:
- exclusion:
resources:
myresource1
builders:
- critical-block-start
- ... other builders
- critical-block-end
"""
cbs = \
XML.SubElement(xml_parent,
'org.jvnet.hudson.plugins.exclusion.CriticalBlockStart')
cbs.set('plugin', 'Exclusion')
def critical_block_end(parser, xml_parent, data):
"""yaml: critical-block-end
Designate the end of a critical block. Must be used in conjuction with
critical-block-start.
Must also add a build wrapper (exclusion), specifying the resources that
control the critical block. Otherwise, this will have no effect.
Requires Jenkins `Exclusion Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin>`_
Example::
wrappers:
- exclusion:
resources:
myresource1
builders:
- critical-block-start
- ... other builders
- critical-block-end
"""
cbs = \
XML.SubElement(xml_parent,
'org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd')
cbs.set('plugin', 'Exclusion')
class Builders(jenkins_jobs.modules.base.Base):
sequence = 60

View File

@ -969,6 +969,34 @@ def matrix_tie_parent(parser, xml_parent, data):
XML.SubElement(mtp, 'labelName').text = data['node']
def exclusion(parser, xml_parent, data):
"""yaml: exclusion
Add a resource to use for critical sections to establish a mutex on. If
another job specifies the same resource, the second job will wait for the
blocked resource to become available.
Requires the Jenkins `Exclusion Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin>`_
:arg list resources: List of resources to add for exclusion
Example:
.. literalinclude:: /../../tests/wrappers/fixtures/exclusion002.yaml
"""
exl = XML.SubElement(xml_parent,
'org.jvnet.hudson.plugins.exclusion.IdAllocator')
exl.set('plugin', 'Exclusion')
ids = XML.SubElement(exl, 'ids')
resources = data.get('resources', [])
for resource in resources:
dit = \
XML.SubElement(ids,
'org.jvnet.hudson.plugins.exclusion.DefaultIdType')
XML.SubElement(dit, 'name').text = str(resource).upper()
class Wrappers(jenkins_jobs.modules.base.Base):
sequence = 80

View File

@ -41,6 +41,8 @@ jenkins_jobs.builders =
builders-from=jenkins_jobs.modules.builders:builders_from
conditional-step=jenkins_jobs.modules.builders:conditional_step
copyartifact=jenkins_jobs.modules.builders:copyartifact
critical-block-start=jenkins_jobs.modules.builders:critical_block_start
critical-block-end=jenkins_jobs.modules.builders:critical_block_end
gradle=jenkins_jobs.modules.builders:gradle
grails=jenkins_jobs.modules.builders:grails
inject=jenkins_jobs.modules.builders:inject
@ -174,6 +176,7 @@ jenkins_jobs.wrappers =
copy-to-slave=jenkins_jobs.modules.wrappers:copy_to_slave
delivery-pipeline=jenkins_jobs.modules.wrappers:delivery_pipeline
env-file=jenkins_jobs.modules.wrappers:env_file
exclusion=jenkins_jobs.modules.wrappers:exclusion
inject-passwords=jenkins_jobs.modules.wrappers:inject_passwords
inject=jenkins_jobs.modules.wrappers:inject
jclouds=jenkins_jobs.modules.wrappers:jclouds

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd plugin="Exclusion"/>
</builders>
</project>

View File

@ -0,0 +1,2 @@
builders:
- critical-block-end

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<org.jvnet.hudson.plugins.exclusion.CriticalBlockStart plugin="Exclusion"/>
</builders>
</project>

View File

@ -0,0 +1,2 @@
builders:
- critical-block-start

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<org.jvnet.hudson.plugins.exclusion.CriticalBlockStart plugin="Exclusion"/>
<org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd plugin="Exclusion"/>
</builders>
</project>

View File

@ -0,0 +1,3 @@
builders:
- critical-block-start
- critical-block-end

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jvnet.hudson.plugins.exclusion.IdAllocator plugin="Exclusion">
<ids>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
</ids>
</org.jvnet.hudson.plugins.exclusion.IdAllocator>
</buildWrappers>
</project>

View File

@ -0,0 +1,4 @@
wrappers:
- exclusion:
resources:
- myresource

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jvnet.hudson.plugins.exclusion.IdAllocator plugin="Exclusion">
<ids>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE1</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE2</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
</ids>
</org.jvnet.hudson.plugins.exclusion.IdAllocator>
</buildWrappers>
</project>

View File

@ -0,0 +1,5 @@
wrappers:
- exclusion:
resources:
- myresource1
- myresource2

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<org.jvnet.hudson.plugins.exclusion.IdAllocator plugin="Exclusion">
<ids>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE1</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE2</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<org.jvnet.hudson.plugins.exclusion.DefaultIdType>
<name>MYRESOURCE3</name>
</org.jvnet.hudson.plugins.exclusion.DefaultIdType>
</ids>
</org.jvnet.hudson.plugins.exclusion.IdAllocator>
</buildWrappers>
</project>

View File

@ -0,0 +1,6 @@
wrappers:
- exclusion:
resources:
- myResource1
- MyresoUrce2
- myReSoUrCe3