From 7a2f730052ca796d4e3663484a6ba98f055615dc Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Fri, 15 Mar 2019 12:42:55 -0400 Subject: Initial upload of F-GPS seed code 21/21 Includes: API resources Change-Id: I6f09189217fc8424a2ad17be75e42edd0cc8a996 Issue-ID: OPTFRA-440 Signed-off-by: arthur.martella.1@att.com --- valetapi/src/main/jenkins/versioning.groovy | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 valetapi/src/main/jenkins/versioning.groovy (limited to 'valetapi/src/main/jenkins/versioning.groovy') diff --git a/valetapi/src/main/jenkins/versioning.groovy b/valetapi/src/main/jenkins/versioning.groovy new file mode 100755 index 0000000..61b21b0 --- /dev/null +++ b/valetapi/src/main/jenkins/versioning.groovy @@ -0,0 +1,66 @@ +#!/usr/bin/env groovy +// Construct tag version from pom version and pipelineId input param +def set(String version, String pipelineId) { + if (pipelineId == "") { + //id empty, default to jenkins build info + echo "pipelineId is empty, defaulting to ${currentBuild.startTimeInMillis}-${currentBuild.number}" + pipelineId = "${currentBuild.startTimeInMillis}-${currentBuild.number}" + } else { + echo "pipelineId is ${pipelineId}" + } + + TAG_VERSION = VERSION.replace("-SNAPSHOT", "") + "-" + pipelineId + currentBuild.displayName = "${TAG_VERSION}" + def previousDesc = currentBuild.description + currentBuild.description = "${previousDesc} TAG_VERSION=${TAG_VERSION}" + stage "SetVersion|" + TAG_VERSION +} + +// Uses Maven Release Plugin +// Creates SCM tag of format - +// Retains POM version of branch as +// should be Jenkins SSH credential with permissions to write to Repo +// WARNING: when implementing auto-tagging, update CodeCloud Web Hook to filter out tag updates (i.e. add ^$ to tag filter) +def tagScm(String artifact, String devVersion, String tagVersion, String credentialId) { + + if (env.BRANCH_NAME == 'master') { + stage 'Tag SCM' + sh "git clean -f && git reset --hard origin/${env.BRANCH_NAME}" + + //TODO - NEED TO INCREMENT VERSION SOMEWHERE OR ADD SOMETHING ABOUT BRANCH IN TAGVERSION + // MASTER AND RELEASE BRANCHES COULD STEP ON EACH OTHER IF TEAMS DON'T MANAGE THE POM + // VERSION ADEQUATELY + + //TODO - evaluate if we want to edit the version in the pom or just use in the tag name? + // need to take into account how a branch will be created from the tag and what the + // versioning of that branch should be, and what the auto process does with it + // How to handle modification of snapshot (1.0.0-SNAPSHOT) vs. release (1.0.0) versions + + + + + // Run the maven build this is a release that keeps the development version + // unchanged and uses Jenkins to provide the version number uniqueness + sh "mvn -s ${MAVEN_SETTINGS} -DreleaseVersion=${tagVersion} -DdevelopmentVersion=${devVersion} -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize release:prepare release:perform -B" + + // push the tags (alternatively we could have pushed them to a separate + // git repo that we then pull from and repush... the latter can be + // helpful in the case where you run the publish on a different node + + //TODO logic needed to get credentialId and determine if https or ssh is use, to use credentials differently on push + //withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'git_m09262', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { + sshagent([credentialId]) { + sh "git remote -v" + sh "git push origin ${artifact}-${tagVersion}" + } + + + // we should also release the staging repo, if we had stashed the + //details of the staging repository identifier it would be easy + + } else { + echo "version.setTag() not in branch 'master', no action performed" + } +} + +return this; \ No newline at end of file -- cgit 1.2.3-korg