Skip to content

Instantly share code, notes, and snippets.

@epishan
Last active September 7, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epishan/2fd33944541585cbb38a094cec58aea5 to your computer and use it in GitHub Desktop.
Save epishan/2fd33944541585cbb38a094cec58aea5 to your computer and use it in GitHub Desktop.
// this script will reuse GIT_BRANCH variable from the last successful job, if current BRANCH parameter is empty
def branch="$BRANCH"
println "currentJob --> ${currentJob}"
println "currentBuild --> ${currentBuild}"
if (branch=="") {
try {
println "setting BRANCH from the last build"
def lastBuild = currentJob.lastSuccessfulBuild
println "lastBuild -> ${lastBuild}"
//branch = lastBuild.getBuildVariables().get("BRANCH");
def git_branch = lastBuild.envVars['GIT_BRANCH']
branch = git_branch.split('/',2)[1]
} catch (error) {
println "ERROR -> ${error}"
branch=""
}
}
println "currentBranch --> ${branch}"
def map = [BRANCH: "${branch}"]
return map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment