Jenkins通过特定标签触发构建

时间:2017-07-19 20:26:06

标签: git jenkins tags

有人可以告诉我如何根据特定标签设置jenkins来构建git仓库吗?我已经完成了一些搜索并尝试设置作业以构建特定标记,请参阅:Jenkins Git Plugin: How to build specific tag? 但我只能从主分支中提取最新的提交。

这是针对詹金斯2.54的。我在SCM下设置了以下内容。

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

在构建触发器下,我允许所有分支触发此作业。 我有一个使用jenkins-test1.0标记的提交,当我从gitlab测试webhook时,它成功地启动了jenkins作业,但它从主分支中提取最新的提交,而不是标记的提交。

提前致谢...

1 个答案:

答案 0 :(得分:0)

您可以使用Generic Webhook Trigger Plugin执行此操作。

来自其中一个测试用例:

场景:应在创建标记时触发构建,而不是在删除标记时触发。

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":"git@example.com: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      | git@example.com:jsmith/example.git       |