From f74501e781fe8d01e2a978557131ffbb48442a11 Mon Sep 17 00:00:00 2001 From: Madhumitha Viswanathan Date: Mon, 25 Apr 2016 13:14:56 -0700 Subject: [PATCH] Add partial support for maven-release-plugin This patch adds support for the Maven release build wrapper. The Maven release plugin makes use of the concept of jenkins Actions to trigger the actual release - https://wiki.jenkins-ci.org/display/JENKINS/Action+and+its+family+of+subtypes The actual code for the action - https://github.com/jenkinsci/m2release-plugin/blob/master/ src/main/java/org/jvnet/hudson/plugins/m2release/M2ReleaseAction.java, seems to put together all the required parameters and makes a call to scheduleBuild2 and passes an Action object with it. Afaik, JJB doesn't support the concept of Actions. If the M2ReleaseAction was an instance of Builder, instead of Action it would work with this. Currently, I don't see how the actual build (release) can be triggered from JJB config, and it seems like we can define the build wrapper alone as part of the job definition, and would still have to trigger the release from the UI for the job like - /m2release Change-Id: Ifc979cdb8e40ad31debff04f745649f23f7ef91a --- jenkins_jobs/modules/wrappers.py | 49 +++++++++++++++++++ tests/wrappers/fixtures/maven-release001.xml | 16 ++++++ tests/wrappers/fixtures/maven-release001.yaml | 10 ++++ tests/wrappers/fixtures/maven-release002.xml | 16 ++++++ tests/wrappers/fixtures/maven-release002.yaml | 10 ++++ 5 files changed, 101 insertions(+) create mode 100644 tests/wrappers/fixtures/maven-release001.xml create mode 100644 tests/wrappers/fixtures/maven-release001.yaml create mode 100644 tests/wrappers/fixtures/maven-release002.xml create mode 100644 tests/wrappers/fixtures/maven-release002.yaml diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 7c75b4b4e..76255cd4e 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -2180,6 +2180,55 @@ def artifactory_maven_freestyle(parser, xml_parent, data): artifactory_optional_props(artifactory, data, 'wrappers') +def maven_release(parser, xml_parent, data): + """yaml: maven-release + Wrapper for Maven projects + Requires :jenkins-wiki:`M2 Release Plugin ` + + :arg str release-goals: Release goals and options (default '') + :arg str dry-run-goals: DryRun goals and options (default '') + :arg int num-successful-builds: Number of successful release builds to keep + (default 1) + :arg bool select-custom-scm-comment-prefix: Preselect 'Specify custom SCM + comment prefix' (default false) + :arg bool select-append-jenkins-username: Preselect 'Append Jenkins + Username' (default false) + :arg bool select-scm-credentials: Preselect 'Specify SCM login/password' + (default false) + :arg str release-env-var: Release environment variable (default '') + :arg str scm-user-env-var: SCM username environment variable (default '') + :arg str scm-password-env-var: SCM password environment variable + (default '') + + Example: + + .. literalinclude:: /../../tests/wrappers/fixtures/maven-release001.yaml + :language: yaml + + """ + mvn_release = XML.SubElement(xml_parent, + 'org.jvnet.hudson.plugins.m2release.' + 'M2ReleaseBuildWrapper') + XML.SubElement(mvn_release, 'releaseGoals').text = str( + data.get('release-goals', '')) + XML.SubElement(mvn_release, 'dryRunGoals').text = str( + data.get('dry-run-goals', '')) + XML.SubElement(mvn_release, 'numberOfReleaseBuildsToKeep').text = str( + data.get('num-successful-builds', '1')) + XML.SubElement(mvn_release, 'selectCustomScmCommentPrefix').text = str( + data.get('select-custom-scm-comment-prefix', 'false')).lower() + XML.SubElement(mvn_release, 'selectAppendHudsonUsername').text = str( + data.get('select-append-jenkins-username', 'false')).lower() + XML.SubElement(mvn_release, 'selectScmCredentials').text = str( + data.get('select-scm-credentials', 'false')).lower() + XML.SubElement(mvn_release, 'releaseEnvVar').text = str( + data.get('release-env-var', '')) + XML.SubElement(mvn_release, 'scmUserEnvVar').text = str( + data.get('scm-user-env-var', '')) + XML.SubElement(mvn_release, 'scmPasswordEnvVar').text = str( + data.get('scm-password-env-var', '')) + + class Wrappers(jenkins_jobs.modules.base.Base): sequence = 80 diff --git a/tests/wrappers/fixtures/maven-release001.xml b/tests/wrappers/fixtures/maven-release001.xml new file mode 100644 index 000000000..9a885ca51 --- /dev/null +++ b/tests/wrappers/fixtures/maven-release001.xml @@ -0,0 +1,16 @@ + + + + + -Dresume=false release:prepare release:perform + -Dresume=false -DdryRun=true release:prepare + 1 + false + false + false + IS_M2RELEASEBUILD + SCM_USER + + + + diff --git a/tests/wrappers/fixtures/maven-release001.yaml b/tests/wrappers/fixtures/maven-release001.yaml new file mode 100644 index 000000000..02f3afb1d --- /dev/null +++ b/tests/wrappers/fixtures/maven-release001.yaml @@ -0,0 +1,10 @@ +wrappers: + - maven-release: + release-goals: -Dresume=false release:prepare release:perform + dry-run-goals: -Dresume=false -DdryRun=true release:prepare + num-successful-builds: 1 + select-custom-scm-comment-prefix: false + select-append-jenkins-username: false + select-scm-credentials: false + release-env-var: IS_M2RELEASEBUILD + scm-user-env-var: SCM_USER diff --git a/tests/wrappers/fixtures/maven-release002.xml b/tests/wrappers/fixtures/maven-release002.xml new file mode 100644 index 000000000..42941ef3d --- /dev/null +++ b/tests/wrappers/fixtures/maven-release002.xml @@ -0,0 +1,16 @@ + + + + + -Dresume=false release:prepare release:perform + -Dresume=false -DdryRun=true release:prepare + 2 + true + false + true + + SCM_USER + SCM_PASSWORD + + + diff --git a/tests/wrappers/fixtures/maven-release002.yaml b/tests/wrappers/fixtures/maven-release002.yaml new file mode 100644 index 000000000..4102b2ea5 --- /dev/null +++ b/tests/wrappers/fixtures/maven-release002.yaml @@ -0,0 +1,10 @@ +wrappers: + - maven-release: + release-goals: -Dresume=false release:prepare release:perform + dry-run-goals: -Dresume=false -DdryRun=true release:prepare + num-successful-builds: 2 + select-custom-scm-comment-prefix: true + select-append-jenkins-username: false + select-scm-credentials: true + scm-user-env-var: SCM_USER + scm-password-env-var: SCM_PASSWORD