From b400742224c49c0035d2cadc310f8e6ead7fa37a Mon Sep 17 00:00:00 2001 From: Gabriele Cerami Date: Fri, 7 Feb 2014 16:25:37 +0100 Subject: [PATCH] Added support for python virtualenv plugin Change-Id: Ie21699d43ff6331ae93cc83d8f9751ac683b43fa --- jenkins_jobs/modules/builders.py | 123 ++++++++++++++++++ setup.py | 2 + .../fixtures/shining-panda-customenv.xml | 13 ++ .../fixtures/shining-panda-customenv.yaml | 9 ++ .../fixtures/shining-panda-pythonenv.xml | 11 ++ .../fixtures/shining-panda-pythonenv.yaml | 7 + .../fixtures/shining-panda-virtualenv.xml | 15 +++ .../fixtures/shining-panda-virtualenv.yaml | 11 ++ 8 files changed, 191 insertions(+) create mode 100644 tests/builders/fixtures/shining-panda-customenv.xml create mode 100644 tests/builders/fixtures/shining-panda-customenv.yaml create mode 100644 tests/builders/fixtures/shining-panda-pythonenv.xml create mode 100644 tests/builders/fixtures/shining-panda-pythonenv.yaml create mode 100644 tests/builders/fixtures/shining-panda-virtualenv.xml create mode 100644 tests/builders/fixtures/shining-panda-virtualenv.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 5d114c774..e995c3e22 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 + `_. + + :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() diff --git a/setup.py b/setup.py index 5437784bf..2c337573d 100644 --- a/setup.py +++ b/setup.py @@ -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 000000000..8fccbe867 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-customenv.xml @@ -0,0 +1,13 @@ + + + + + /usr/local/lib/custom-python-27 + xshell + cd $HOME/build +python setup.py build + + true + + + diff --git a/tests/builders/fixtures/shining-panda-customenv.yaml b/tests/builders/fixtures/shining-panda-customenv.yaml new file mode 100644 index 000000000..54463eaa5 --- /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 000000000..f7a06a389 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-pythonenv.xml @@ -0,0 +1,11 @@ + + + + + System-CPython-2.7 + python + setup.py build + false + + + diff --git a/tests/builders/fixtures/shining-panda-pythonenv.yaml b/tests/builders/fixtures/shining-panda-pythonenv.yaml new file mode 100644 index 000000000..50522ddc0 --- /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 000000000..96fb37879 --- /dev/null +++ b/tests/builders/fixtures/shining-panda-virtualenv.xml @@ -0,0 +1,15 @@ + + + + + System-CPython-2.7 + virtvenv1 + true + true + true + shell + python setup.py build + true + + + diff --git a/tests/builders/fixtures/shining-panda-virtualenv.yaml b/tests/builders/fixtures/shining-panda-virtualenv.yaml new file mode 100644 index 000000000..97a9a6513 --- /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