首页 文章

Jenkins通过特定标签触发构建

提问于
浏览
1

有人能告诉我如何设置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

    您可以使用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       |
    

相关问题