With jenkins pipeline the GIT_BRANCH
environment variable disappeared.
One the one hand this is obvious since you can work with several scms in
one pipeline, on the other hand this functionality is handy when you are
working with one scm.
Calling this step will bring back this functionality by setting the
GIT_BRANCH
to the best available value.
💡 This step works best when you add the LocalBranch
extension
during scm checkout:
or via checkoutScm
step. See
Example 4
💡 If you are using the checkoutScm
step from
the library this step will be automatically called for your convenience.
These steps are executed by the step in order to detect/retrieve the
GIT_BRANCH
- Check if
GIT_BRANCH
is already available - Check if
BRANCH_NAME
environment variable is set (this is the case in Multibranch pipeline builds) - Try to retrieve via executing
git branch
(Therefore theLocalBranch
extension has to be enabled) - Fallback: Use the short git commit hash