Add the Slave Prerequisites properties plugin

Add support for the Slave Prerequisites Plugin
(https://wiki.jenkins-ci.org/display/JENKINS/Slave+Prerequisites+Plugin)

Change-Id: I98e854ab3ab7cdbe1563b6b38b7fc4d661edcd11
This commit is contained in:
Alexander Evseev 2017-03-06 14:26:09 +03:00
parent a5eb235881
commit 273f2128fe
5 changed files with 73 additions and 0 deletions

View File

@ -849,6 +849,44 @@ def build_discarder(registry, xml_parent, data):
strategy, data, mappings, fail_required=True)
def slave_prerequisites(registry, xml_parent, data):
"""yaml: slave-prerequisites
This plugin allows to check prerequisites on slave before
a job can run a build on it
Requires the Jenkins :jenkins-wiki:`Slave Prerequisites Plugin
<Slave+Prerequisites+Plugin>`.
:arg str script: A script to be executed on slave node.
If returning non 0 status, the node will be vetoed from hosting
the build. (required)
:arg str interpreter: Command line interpreter to be used for executing
the prerequisite script - either `shell` for Unix shell or `cmd` for
Windows batch script. (default shell)
Example:
.. literalinclude::
/../../tests/properties/fixtures/slave-prerequisites-minimal.yaml
:language: yaml
.. literalinclude::
/../../tests/properties/fixtures/slave-prerequisites-full.yaml
:language: yaml
"""
prereqs = XML.SubElement(xml_parent,
'com.cloudbees.plugins.JobPrerequisites')
mappings = [
('script', 'script', None),
('interpreter', 'interpreter', 'shell', {
'cmd': 'windows batch command',
'shell': 'shell script'}),
]
helpers.convert_mapping_to_xml(
prereqs, data, mappings, fail_required=True)
class Properties(jenkins_jobs.modules.base.Base):
sequence = 20

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<com.cloudbees.plugins.JobPrerequisites>
<script>@echo off
if exist C:\Jenkins\workspace.lock exit /b 1
</script>
<interpreter>windows batch command</interpreter>
</com.cloudbees.plugins.JobPrerequisites>
</properties>
</project>

View File

@ -0,0 +1,6 @@
properties:
- slave-prerequisites:
interpreter: cmd
script: |
@echo off
if exist C:\Jenkins\workspace.lock exit /b 1

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<com.cloudbees.plugins.JobPrerequisites>
<script>#!/bin/bash
AVAILABLE=$(df -BG --output=avail / | tail -1)
test ${AVAILABLE%G} -ge 10
</script>
<interpreter>shell script</interpreter>
</com.cloudbees.plugins.JobPrerequisites>
</properties>
</project>

View File

@ -0,0 +1,6 @@
properties:
- slave-prerequisites:
script: |
#!/bin/bash
AVAILABLE=$(df -BG --output=avail / | tail -1)
test ${AVAILABLE%G} -ge 10