jenkins does not trigger build when a new tag is pushed on the same commit jenkins does not trigger build when a new tag is pushed on the same commit jenkins jenkins

jenkins does not trigger build when a new tag is pushed on the same commit


I was facing the same issue and created a workaround for that. I decided to tag with suffix _uat, _prod etc. which helped me to achieve the goal. You will also require two Jenkins jobs for that. One will trigger another if condition matched.

Step 1git tag -a release-v1_uat -m "Commit message"
git push origin release-v1_uat

Create two Jenkins Jobs

Job 1
Define repository
In Advance section's "Refspec" field put:
+refs/tags/_uat:refs/remotes/origin/tags/_uat

In "Branches to build" section:
**/tags/*_uat

BuildTriggers
CHECK-> GitHub hook trigger for GITScm polling

BUILDSTEP
ExecuteShell
TAG=$(git describe --tags --abbrev=0)
echo $TAG
echo $TAG > /tmp/tagname
result=echo $TAG | sed 's/.*\(....\)/\1/'
if [[ $result == _uat ]]; then echo yes; else (exit 1); fi

Click on Advance right below execute shell
Exit code to set build unstable (It will prevent the job to get triggered from any other Tag)
Put 1 in the Box

Post-build Actions
Check: Delete WorkSpace After Build

Job 2 (Your Main Job)
Go to "Build after other projects are built"
Mention you job 1 name in the box and select "Trigger only if build is stable"

Do not forget to get your tag value from the file by doing cat /tmp/tagname which generated in the job 1

There is always a room for improvement, please share if you have some better workaround/solution.