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

Jenkins delete jobs when branch deleted via branch-indexing

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

由于您使用的是最新的 Jenkins 版本,请考虑将您的工作切换到 multibranch pipeline setup

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.

编辑:检查管道的 'Discard Old Items' 设置。如果你有非零 'Max # of old items' 那么,如果你的分支的构建少于这个数字,它永远不会被删除!您甚至可以在日志中看到:

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

编辑:您还可以通过添加名为 "Prune stale remote-tracking branches" 的额外行为来试试运气("Behaviors" -> "Add" -> Select 来自下拉菜单)。

1) 转到 Manage Jenkins -> Global Tool Configuration -> Git -> Add Git -> Choose JGit.

2) 然后转到您的多分支管道配置并在 Branch Sources -> Git Executable

下选择 JGit 而不是 Default

3) 按Branch Indexing -> Run now

旧分支现在应该消失