使用 Jenkins Git Publisher 推送标签 - 多个 Git 存储库(分叉)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18650658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:01:17  来源:igfitidea点击:

Pushing tags with Jenkins Git Publisher - multiple Git repositories (forks)

gitjenkinsgitlab

提问by Nicholas Albion

Our team is transitioning from CVS to Git. We intend to use the similar workflow as most open source projects on GitHub - each developer takes a fork of the main repo and then submits a pull request which will allow the project master to do a code review before merging the changes into the main repo.

我们的团队正在从 CVS 过渡到 Git。我们打算使用与 GitHub 上大多数开源项目类似的工作流程——每个开发人员获取主存储库的一个分支,然后提交一个拉取请求,这将允许项目管理员在将更改合并到主存储库之前进行代码。

Jenkins allows us to add multiple Git repositories (the standard Git plugin, not the Multiple SCM one). Presumably I can enter the URL for each forked repo and then Jenkins will check all branches each fork for changes. I give each repository a name eg "master", "developer1", "developer2"...

Jenkins 允许我们添加多个 Git 存储库(标准 Git 插件,而不是 Multiple SCM 插件)。大概我可以为每个分叉的 repo 输入 URL,然后 Jenkins 将检查每个分叉的所有分支是否有更改。我给每个存储库一个名称,例如“master”、“developer1”、“developer2”...

We want to have Jenkins tagging each build on the appropriate remote/fork. The Git Publisher plugin requires that you provide the "target remote name", but we need Jenkins to be able to figure this out for itself.

我们想让 Jenkins 在适当的远程/分叉上标记每个构建。Git Publisher 插件要求您提供“目标远程名称”,但我们需要 Jenkins 自己解决这个问题。

回答by Nicholas Albion

I've managed to solve this one myself.

我已经设法自己解决了这个问题。

  • At the top of the Jenkins project config page check "This build is parameterized" and add a string parameter "remote" with default "master".
  • Add "Git Publisher" as a Post-build action, and a Tag "$BUILD_TAG" and Target remote name = "$remote"
  • In Build Triggers, check "Trigger builds remotely"
  • We're using GitLab and under the project Settings menu I add a "Web Hook":

    http://my-jenkins-server.com/job/my-project/buildWithParameters?token=secret&remote=master

  • 在 Jenkins 项目配置页面的顶部,选中“This build is parameterized”并添加一个字符串参数“remote”,默认为“master”。
  • 添加“Git Publisher”作为构建后操作,以及标签“$BUILD_TAG”和目标远程名称=“$remote”
  • 在构建触发器中,选中“远程触发构建”
  • 我们正在使用 GitLab,在项目设置菜单下,我添加了一个“Web Hook”:

    http://my-jenkins-server.com/job/my-project/buildWithParameters?token=secret&remote=master

Add a web hook for each fork, and make sure that the "remote" parameter matches the repository name configured in Jenkins.

为每个 fork 添加一个 web hook,并确保“remote”参数与 Jenkins 中配置的存储库名称匹配。