From dcfe7696d05a7389c6d84c52e824892b425f43b7 Mon Sep 17 00:00:00 2001 From: Eli Klein Date: Mon, 27 Jan 2014 20:12:06 -0700 Subject: [PATCH] Added clone-workspace publisher Change-Id: I39c71d69b100206e09164f0b765bda14d6f428c6 --- jenkins_jobs/modules/publishers.py | 71 +++++++++++++++++++ setup.py | 1 + .../fixtures/clone-workspace001.xml | 11 +++ .../fixtures/clone-workspace001.yaml | 2 + .../fixtures/clone-workspace002.xml | 12 ++++ .../fixtures/clone-workspace002.yaml | 7 ++ 6 files changed, 104 insertions(+) create mode 100644 tests/publishers/fixtures/clone-workspace001.xml create mode 100644 tests/publishers/fixtures/clone-workspace001.yaml create mode 100644 tests/publishers/fixtures/clone-workspace002.xml create mode 100644 tests/publishers/fixtures/clone-workspace002.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c68295717..d8d388b4d 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -254,6 +254,77 @@ def trigger(parser, xml_parent, data): tcolor.text = thresholds[threshold]['color'] +def clone_workspace(parser, xml_parent, data): + """yaml: clone-workspace + Archive the workspace from builds of one project and reuse them as the SCM + source for another project. + Requires the Jenkins `Clone Workspace SCM Plugin. + `_ + + :arg str workspace-glob: Files to include in cloned workspace + :arg str workspace-exclude-glob: Files to exclude from cloned workspace + :arg str criteria: Criteria for build to be archived. Can be 'any', + 'not failed', or 'successful'. (default: any ) + :arg str archive-method: Choose the method to use for archiving the + workspace. Can be 'tar' or 'zip'. (default: tar) + :arg bool override-default-excludes: Override default ant excludes. + (default: false) + + Minimal example: + + .. literalinclude:: + /../../tests/publishers/fixtures/clone-workspace001.yaml + + Full example: + + .. literalinclude:: + /../../tests/publishers/fixtures/clone-workspace002.yaml + + """ + + cloneworkspace = XML.SubElement( + xml_parent, + 'hudson.plugins.cloneworkspace.CloneWorkspacePublisher', + {'plugin': 'clone-workspace-scm'}) + + XML.SubElement( + cloneworkspace, + 'workspaceGlob').text = data.get('workspace-glob', None) + + if 'workspace-exclude-glob' in data: + XML.SubElement( + cloneworkspace, + 'workspaceExcludeGlob').text = data['workspace-exclude-glob'] + + criteria_list = ['Any', 'Not Failed', 'Successful'] + + criteria = data.get('criteria', 'Any').title() + + if 'criteria' in data and criteria not in criteria_list: + raise JenkinsJobsException( + 'clone-workspace criteria must be one of: ' + + ', '.join(criteria_list)) + else: + XML.SubElement(cloneworkspace, 'criteria').text = criteria + + archive_list = ['TAR', 'ZIP'] + + archive_method = data.get('archive-method', 'TAR').upper() + + if 'archive-method' in data and archive_method not in archive_list: + raise JenkinsJobsException( + 'clone-workspace archive-method must be one of: ' + + ', '.join(archive_list)) + else: + XML.SubElement(cloneworkspace, 'archiveMethod').text = archive_method + + XML.SubElement( + cloneworkspace, + 'overrideDefaultExcludes').text = str(data.get( + 'override-default-excludes', + False)).lower() + + def cloverphp(parser, xml_parent, data): """yaml: cloverphp Capture code coverage reports from PHPUnit diff --git a/setup.py b/setup.py index 4a7c542b9..cb8a0ed81 100644 --- a/setup.py +++ b/setup.py @@ -127,6 +127,7 @@ setuptools.setup( 'checkstyle=jenkins_jobs.modules.publishers:checkstyle', 'cifs=jenkins_jobs.modules.publishers:cifs', 'claim-build=jenkins_jobs.modules.publishers:claim_build', + 'clone-workspace=jenkins_jobs.modules.publishers:clone_workspace', 'cloverphp=jenkins_jobs.modules.publishers:cloverphp', 'cobertura=jenkins_jobs.modules.publishers:cobertura', 'copy-to-master=jenkins_jobs.modules.publishers:copy_to_master', diff --git a/tests/publishers/fixtures/clone-workspace001.xml b/tests/publishers/fixtures/clone-workspace001.xml new file mode 100644 index 000000000..8fb6c68e5 --- /dev/null +++ b/tests/publishers/fixtures/clone-workspace001.xml @@ -0,0 +1,11 @@ + + + + + + Any + TAR + false + + + diff --git a/tests/publishers/fixtures/clone-workspace001.yaml b/tests/publishers/fixtures/clone-workspace001.yaml new file mode 100644 index 000000000..c354b9e4a --- /dev/null +++ b/tests/publishers/fixtures/clone-workspace001.yaml @@ -0,0 +1,2 @@ +publishers: + - clone-workspace diff --git a/tests/publishers/fixtures/clone-workspace002.xml b/tests/publishers/fixtures/clone-workspace002.xml new file mode 100644 index 000000000..00e032d6a --- /dev/null +++ b/tests/publishers/fixtures/clone-workspace002.xml @@ -0,0 +1,12 @@ + + + + + **/*.zip + **/*.tgz + Any + TAR + false + + + diff --git a/tests/publishers/fixtures/clone-workspace002.yaml b/tests/publishers/fixtures/clone-workspace002.yaml new file mode 100644 index 000000000..c7b0f477b --- /dev/null +++ b/tests/publishers/fixtures/clone-workspace002.yaml @@ -0,0 +1,7 @@ +publishers: + - clone-workspace: + criteria: "any" + archive-method: "tar" + override-default-excludes: false + workspace-glob: "**/*.zip" + workspace-exclude-glob: "**/*.tgz"