Created
November 23, 2018 16:02
-
-
Save Sysa/6d4085e50c1bcadcba7252b8c147fac7 to your computer and use it in GitHub Desktop.
get and filter git branch in jenkins pipeline
This file contains hidden or 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
stage("git remote"){ | |
withCredentials([usernamePassword(credentialsId: 'git_worker', passwordVariable: 'PASS', usernameVariable: 'USERNAME')]) { | |
String filterBranch = "release/" | |
String sh_git_result = sh(script: "git ls-remote http://${USERNAME}:${PASS}@bitbucket.yourdomain.com/scm/rpl/client.git | grep ${filterBranch}", returnStdout: true).trim() | |
println sh_git_result | |
//regex to take only `release/01.02` from `refs/heads/release/01.02-fake-239` - (?<=heads\/).*(?<=\d{2}\.\d{2}) | |
// to take only `release/*` -> (?<=heads\/).* | |
branch_result = (sh_git_result =~ /(?<=heads\/).*/)[0] | |
println branch_result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment