To fetch the latest commit from branchName
, we run below code:
treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
It is ensured that there is one tag per commit, as per our workflow
We want to build the code, only if the commit is tagged.
How to retrieve the tag name for that latest commit?
We can fetch the tags from the repo in case Jenkins hasn't already.
We need to find a tag(s) which point to a specific commit or
HEAD
in our case. Thankfully there is a handy command in git which allows us to do this.Using
awk
we can turn this into an output which groovy can falsify.So we, first we check if the pushed branch is master
lock it down
execute the git tag shell script and assign it to TAG
if a tag exists, do something!
Hopefully this answers your question, or at the very least will get you on the right track.