【问题标题】:Jenkins trigger build via specific tagJenkins 通过特定标签触发构建
【发布时间】:2017-12-25 07:19:11
【问题描述】:

谁能告诉我如何设置 jenkins 以基于特定标签从 git repo 构建?我做了一些搜索并尝试设置一个工作来构建一个特定的标签,请参阅:Jenkins Git Plugin: How to build specific tag? 但我只能从 master 分支中提取最新的提交。

这是针对詹金斯 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 作业,但它从 master 分支中提取了最新的提交,而不是标记的提交。

提前谢谢...

【问题讨论】:

  • 你找到答案了吗?

标签: git jenkins tags


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-26
    • 2021-09-19
    • 2012-04-29
    • 1970-01-01
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多