Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a Jenkins pipeline by tagging an existing commit

Tags:

git

jenkins

Description

I have Jenkins (2.126) set up to build a pipeline when a new tag is pushed. Specifically, I want to tag an existing commit on master as release-3 and have it trigger a build. According to several sources, what I want is possible:

https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/136740885/Triggering+Jenkins+Based+on+New+Tags

Unfortunately, nothing happens when I tag an existing commit and push it to the Git repository. Other builds (triggered by branches) work as expected, and the tag-triggered build in question completes successfully when started manually.

According to some, tag-triggered pipelines should work since version 2.3. Is there anything I can configure to make it work?

Screenshots of attempts

Attempt with a normal pipeline polling at * * * * *:

enter image description here

Attempt with a multibranch pipeline, scanning every 1 minute:

enter image description here

Related issues

I found the following issues related to the problem, which is supposed to be resolved.

  • https://issues.jenkins-ci.org/browse/JENKINS-38921
  • https://issues.jenkins-ci.org/browse/JENKINS-34176
  • https://issues.jenkins-ci.org/browse/JENKINS-14917
  • https://issues.jenkins-ci.org/browse/JENKINS-47077
  • https://issues.jenkins-ci.org/browse/JENKINS-47891
  • https://issues.jenkins-ci.org/browse/JENKINS-52376
like image 203
Jodiug Avatar asked Jun 09 '18 21:06

Jodiug


1 Answers

You can use Generic Webhook Trigger Plugin.

In GitHub:

  1. Set a webhook in GitHub to invoke JENKINS_URL/generic-webhook-trigger/invoke?some-token-here

In Jenkins:

  1. Create a job and enable the Generic Trigger under "Triggers"
  2. Configure a variable named ref with JSONPath $.ref
  3. Set the filter text to $ref
  4. Set the filter regexp to ^(refs/tags/.+)$
  5. Set the token to some-token-here

Now when a tag is pushed to the repo this job will trigger.

You may also want to pick other values from the webhook like $.repository.ssh_url to get the SSH clone URL.

like image 169
Tomas Bjerre Avatar answered Oct 21 '22 11:10

Tomas Bjerre