Using the Branchname only, instead the full path only

46 views
Skip to first unread message

Paul McGregory

unread,
Dec 12, 2017, 8:04:07 AM12/12/17
to Jenkins Users
Hi Everybody. 

I am using multibranch pipeline.
The deployment works fine, but ein want get the BranchName only, instead the full branchname path. 

e.g I am using echo "${env.BRANCH_NAME}" and get "feature/1234", but I just want "1234".

If found something like echo "${env.BRANCH_NAME}#*feature/" or "${env.BRANCH_NAME}##feature/", but this doesnt work with the pipeline



Stephen Connolly

unread,
Dec 12, 2017, 8:50:39 AM12/12/17
to jenkins...@googlegroups.com
echo "${BRANCH_NAME.replaceAll('^.*/','')}"

or

sh 'echo "${BRANCH_NAME}" | sed -e "s:^.*/::"'

Note the second one needs the careful quoting so that the shell does the expansion

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/deef32e8-98ab-42ba-9ac2-b30238e6e4c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages