Last active
September 7, 2016 13:05
-
-
Save epishan/2fd33944541585cbb38a094cec58aea5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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