1
votes

Can someone tell me how to setup jenkins to build from a git repo based on a specific tag? I've done some searching and tried to setup a job to build off a specific tag, see: Jenkins Git Plugin: How to build specific tag? but I'm only able to pull the latest commit from the master branch.

This is for jenkins 2.54. I have setup the following under SCM.

Repo URL and Credentials
name:  ref
Refspec: +refs/tags*:refs/remotes/origin/tags/*
Branch Specifier refs/tags/jenkins-test*

And under build trigger I have allow all branches to trigger this job. I have a commit tagged with jenkins-test1.0 and when I test the webhook from gitlab, it succesfully kicks off the jenkins job, but its pulling the latest commit from the master branch, and not the tagged commit.

Thanks in advance...

1
did you ever find an answer to this? - dim_user

1 Answers

0
votes

You can use Generic Webhook Trigger Plugin to do this.

From one of the test cases:

Scenario: A build should be triggered when tag is created, not when it is removed.

Given the following generic variables are configured:
  | variable        | expression               | expressionType  | defaultValue | regexpFilter  |
  | object_kind     | $.object_kind            | JSONPath        |              |               |
  | before          | $.before                 | JSONPath        |              |               |
  | after           | $.after                  | JSONPath        |              |               |
  | ref             | $.ref                    | JSONPath        |              |               |
  | git_ssh_url     | $.repository.git_ssh_url | JSONPath        |              |               |

Given filter is configured with text: $object_kind $before $after
Given filter is configured with expression: ^tag_push\s0{40}\s.{40}$

Given received post content is:
"""
{
  "object_kind": "tag_push",
  "before": "0000000000000000000000000000000000000000",
  "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7",
  "ref": "refs/tags/v1.0.0",
  "repository":{
    "git_ssh_url":"[email protected]:jsmith/example.git",
  }
}
"""
Then the job is triggered
Then variables are resolved to:
  | variable         | value                                    |
  | object_kind      | tag_push                                 |
  | before           | 0000000000000000000000000000000000000000 |
  | after            | 82b3d5ae55f7080f1e6022629cdb57bfae7cccc7 |
  | ref              | refs/tags/v1.0.0                         |
  | git_ssh_url      | [email protected]:jsmith/example.git       |