git Jenkins 在通过分支索引删除分支时删除作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37210799/
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-09 04:10:25  来源:igfitidea点击:

Jenkins delete jobs when branch deleted via branch-indexing

gitjenkinsjenkins-2

提问by ligi

Is there a way to tell Jenkins (2.2) to remove jobs for branches that were deleted? Currently my build-monitor fills up with branches as the jobs are not deleted. Is there a setting to trigger this behavior or should this be filed as a bug?

有没有办法告诉Jenkins(2.2)删除已删除分支的作业?目前我的构建监视器充满了分支,因为作业没有被删除。是否有触发此行为的设置,还是应该将其作为错误提交?

采纳答案by madhead

Since you are using latest Jenkins version, consider switching your jobs to multibranch pipeline setup.

由于您使用的是最新的 Jenkins 版本,请考虑将您的工作切换到多分支管道设置

The Workflow Multibranch feature (provided by the workflow plugin) provides the following key abilities:

  • Automatic Workflow (job) creation in Jenkins per new branch in the repo (assuming webhooks are registered from GH to Jenkins).

  • Build specific to that child-branch and its unique scm change and build history.

  • Automatic job pruning/deletion for branches deleted from the repository, according to the settings.

  • Flexibility to individually configure branch properties, by overriding the parent properties, if required.

Workflow Multibranch 功能(由工作流插件提供)提供以下关键功能:

  • 存储库中每个新分支在 Jenkins 中自动创建工作流(作业)(假设 webhooks 从 GH 注册到 Jenkins)。

  • 构建特定于该子分支及其独特的 scm 更改和构建历史。

  • 根据设置,从存储库中删除的分支的自动作业修剪/删除。

  • 如果需要,可以通过覆盖父属性来灵活地单独配置分支属性。

EDIT: check the 'Discard Old Items' settings for you pipeline. If you have non-zero 'Max # of old items' then, if your branch had less builds then this number, it will never be deleted! You can even see that in logs:

编辑:检查管道的“丢弃旧项目”设置。如果您有非零的“旧项目的最大数量”,那么如果您的分支的构建数量少于这个数字,它将永远不会被删除!您甚至可以在日志中看到:

Will not remove US12345 as it is only #1 in the list
Will not remove US23456 as it is only #2 in the list
Will not remove US34567 as it is only #3 in the list

EDIT: You can also try your luck by adding additional behavior named "Prune stale remote-tracking branches" ("Behaviors" -> "Add" -> Select from dropdown).

编辑:您还可以通过添加名为“修剪陈旧的远程跟踪分支”的其他行为来试试运气(“行为”->“添加”-> 从下拉列表中选择)。

回答by StasKolodyuk

1) Go to Manage Jenkins -> Global Tool Configuration -> Git -> Add Git -> Choose JGit.

1) 前往Manage Jenkins -> Global Tool Configuration -> Git -> Add Git -> Choose JGit

2) Then go to your multibranch pipeline configuration and choose JGitinstead Defaultunder Branch Sources -> Git Executable

2)然后去你的多分支管道的配置和选择JGit,而不是DefaultBranch Sources -> Git Executable

3) Press Branch Indexing -> Run now

3) 按 Branch Indexing -> Run now

Old branches should go away now

旧树枝现在应该消失