Added support for python virtualenv plugin

Change-Id: Ie21699d43ff6331ae93cc83d8f9751ac683b43fa
This commit is contained in:
Gabriele Cerami 2014-02-07 16:25:37 +01:00
parent 1ecf6374a6
commit b400742224
8 changed files with 191 additions and 0 deletions

View File

@ -1052,3 +1052,126 @@ class Builders(jenkins_jobs.modules.base.Base):
project_type = data.get('project-type', 'freestyle')
if project_type in ('freestyle', 'matrix') and 'builders' not in data:
XML.SubElement(xml_parent, 'builders')
def shining_panda(parser, xml_parent, data):
"""yaml: shining-panda
Execute a command inside various python environments. Requires the Jenkins
`ShiningPanda plugin
<https://wiki.jenkins-ci.org/display/JENKINS/ShiningPanda+Plugin>`_.
:arg str build-environment: Building environment to set up (Required).
:build-environment values:
* **python**: Use a python installation configured in Jenkins.
* **custom**: Use a manually installed python.
* **virtualenv**: Create a virtualenv
For the **python** environment
:arg str python-version: Name of the python installation to use.
Must match one of the configured installations on server \
configuration
(default: System-CPython-2.7)
For the **custom** environment:
:arg str home: path to the home folder of the custom installation \
(Required)
For the **virtualenv** environment:
:arg str python-version: Name of the python installation to use.
Must match one of the configured installations on server \
configuration
(default: System-CPython-2.7)
:arg str name: Name of this virtualenv. Two virtualenv builders with \
the same name will use the same virtualenv installation (optional)
:arg bool clear: If true, delete and recreate virtualenv on each build.
(default: false)
:arg bool use-distribute: if true use distribute, if false use \
setuptools. (default: true)
:arg bool system-site-packages: if true, give access to the global
site-packages directory to the virtualenv. (default: false)
Common to all environments:
:arg str nature: Nature of the command field. (default: shell)
:nature values:
* **shell**: execute the Command contents with default shell
* **xshell**: like **shell** but performs platform conversion \
first
* **python**: execute the Command contents with the Python \
executable
:arg str command: The command to execute
:arg bool ignore-exit-code: mark the build as failure if any of the
commands exits with a non-zero exit code. (default: false)
Examples:
.. literalinclude:: \
/../../tests/builders/fixtures/shining-panda-pythonenv.yaml
.. literalinclude:: \
/../../tests/builders/fixtures/shining-panda-customenv.yaml
.. literalinclude:: \
/../../tests/builders/fixtures/shining-panda-virtualenv.yaml
"""
pluginelementpart = 'jenkins.plugins.shiningpanda.builders.'
buildenvdict = {'custom': 'CustomPythonBuilder',
'virtualenv': 'VirtualenvBuilder',
'python': 'PythonBuilder'}
envs = (buildenvdict.keys())
try:
buildenv = data['build-environment']
except KeyError:
raise JenkinsJobsException("A build-environment is required")
if buildenv not in envs:
errorstring = ("build-environment '%s' is invalid. Must be one of %s."
% (buildenv, ', '.join("'{0}'".format(env)
for env in envs)))
raise JenkinsJobsException(errorstring)
t = XML.SubElement(xml_parent, '%s%s' %
(pluginelementpart, buildenvdict[buildenv]))
if buildenv in ('python', 'virtualenv'):
XML.SubElement(t, 'pythonName').text = data.get("python-version",
"System-CPython-2.7")
if buildenv in ('custom'):
try:
homevalue = data["home"]
except KeyError:
raise JenkinsJobsException("'home' argument is required for the"
" 'custom' environment")
XML.SubElement(t, 'home').text = homevalue
if buildenv in ('virtualenv'):
XML.SubElement(t, 'home').text = data.get("name", "")
clear = data.get("clear", False)
XML.SubElement(t, 'clear').text = str(clear).lower()
use_distribute = data.get('use-distribute', False)
XML.SubElement(t, 'useDistribute').text = str(use_distribute).lower()
system_site_packages = data.get('system-site-packages', False)
XML.SubElement(t, 'systemSitePackages').text = str(
system_site_packages).lower()
# Common arguments
nature = data.get('nature', 'shell')
naturetuple = ('shell', 'xshell', 'python')
if nature not in naturetuple:
errorstring = ("nature '%s' is not valid: must be one of %s."
% (nature, ', '.join("'{0}'".format(naturevalue)
for naturevalue in naturetuple)))
raise JenkinsJobsException(errorstring)
XML.SubElement(t, 'nature').text = nature
XML.SubElement(t, 'command').text = data.get("command", "")
ignore_exit_code = data.get('ignore-exit-code', False)
XML.SubElement(t, 'ignoreExitCode').text = str(ignore_exit_code).lower()

View File

@ -68,6 +68,8 @@ setuptools.setup(
'maven-target=jenkins_jobs.modules.builders:maven_target',
'msbuild=jenkins_jobs.modules.builders:msbuild',
'multijob=jenkins_jobs.modules.builders:multijob',
('shining-panda=jenkins_jobs.modules.builders:'
'shining_panda'),
'sbt=jenkins_jobs.modules.builders:sbt',
'shell=jenkins_jobs.modules.builders:shell',
'trigger-builds=jenkins_jobs.modules.builders:trigger_builds',

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<jenkins.plugins.shiningpanda.builders.CustomPythonBuilder>
<home>/usr/local/lib/custom-python-27</home>
<nature>xshell</nature>
<command>cd $HOME/build
python setup.py build
</command>
<ignoreExitCode>true</ignoreExitCode>
</jenkins.plugins.shiningpanda.builders.CustomPythonBuilder>
</builders>
</project>

View File

@ -0,0 +1,9 @@
builders:
- shining-panda:
build-environment: custom
home: /usr/local/lib/custom-python-27
nature: xshell
command: |
cd $HOME/build
python setup.py build
ignore-exit-code: true

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<jenkins.plugins.shiningpanda.builders.PythonBuilder>
<pythonName>System-CPython-2.7</pythonName>
<nature>python</nature>
<command>setup.py build</command>
<ignoreExitCode>false</ignoreExitCode>
</jenkins.plugins.shiningpanda.builders.PythonBuilder>
</builders>
</project>

View File

@ -0,0 +1,7 @@
builders:
- shining-panda:
build-environment: python
python-version: System-CPython-2.7
nature: python
command: setup.py build
ignore-exit-code: false

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<jenkins.plugins.shiningpanda.builders.VirtualenvBuilder>
<pythonName>System-CPython-2.7</pythonName>
<home>virtvenv1</home>
<clear>true</clear>
<useDistribute>true</useDistribute>
<systemSitePackages>true</systemSitePackages>
<nature>shell</nature>
<command>python setup.py build</command>
<ignoreExitCode>true</ignoreExitCode>
</jenkins.plugins.shiningpanda.builders.VirtualenvBuilder>
</builders>
</project>

View File

@ -0,0 +1,11 @@
builders:
- shining-panda:
build-environment: virtualenv
python-version: System-CPython-2.7
nature: shell
command: python setup.py build
name: virtvenv1
clear: true
use-distribute: true
system-site-packages: true
ignore-exit-code: true