diff options
author | Gabriele Cerami <gcerami@redhat.com> | 2014-02-07 16:25:37 +0100 |
---|---|---|
committer | Gabriele Cerami <gcerami@redhat.com> | 2014-02-20 21:50:26 +0100 |
commit | b400742224c49c0035d2cadc310f8e6ead7fa37a (patch) | |
tree | 4c8cc6ba7cbd771ceefe3c96117a73e10cb1a8b3 | |
parent | 1ecf6374a67a84acdb1feb64bb61deab50f1960d (diff) | |
download | python-jenkins-job-builder-b400742224c49c0035d2cadc310f8e6ead7fa37a.tar.gz python-jenkins-job-builder-b400742224c49c0035d2cadc310f8e6ead7fa37a.tar.xz python-jenkins-job-builder-b400742224c49c0035d2cadc310f8e6ead7fa37a.zip |
Added support for python virtualenv plugin
Change-Id: Ie21699d43ff6331ae93cc83d8f9751ac683b43fa
-rw-r--r-- | jenkins_jobs/modules/builders.py | 123 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-customenv.xml | 13 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-customenv.yaml | 9 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-pythonenv.xml | 11 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-pythonenv.yaml | 7 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-virtualenv.xml | 15 | ||||
-rw-r--r-- | tests/builders/fixtures/shining-panda-virtualenv.yaml | 11 |
8 files changed, 191 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 5d114c77..e995c3e2 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -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() @@ -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', diff --git a/tests/builders/fixtures/shining-panda-customenv.xml b/tests/builders/fixtures/shining-panda-customenv.xml new file mode 100644 index 00000000..8fccbe86 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-customenv.xml @@ -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> diff --git a/tests/builders/fixtures/shining-panda-customenv.yaml b/tests/builders/fixtures/shining-panda-customenv.yaml new file mode 100644 index 00000000..54463eaa --- /dev/null +++ b/tests/builders/fixtures/shining-panda-customenv.yaml @@ -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 diff --git a/tests/builders/fixtures/shining-panda-pythonenv.xml b/tests/builders/fixtures/shining-panda-pythonenv.xml new file mode 100644 index 00000000..f7a06a38 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-pythonenv.xml @@ -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> diff --git a/tests/builders/fixtures/shining-panda-pythonenv.yaml b/tests/builders/fixtures/shining-panda-pythonenv.yaml new file mode 100644 index 00000000..50522ddc --- /dev/null +++ b/tests/builders/fixtures/shining-panda-pythonenv.yaml @@ -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 diff --git a/tests/builders/fixtures/shining-panda-virtualenv.xml b/tests/builders/fixtures/shining-panda-virtualenv.xml new file mode 100644 index 00000000..96fb3787 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-virtualenv.xml @@ -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> diff --git a/tests/builders/fixtures/shining-panda-virtualenv.yaml b/tests/builders/fixtures/shining-panda-virtualenv.yaml new file mode 100644 index 00000000..97a9a651 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-virtualenv.yaml @@ -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 |