Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins delete jobs when branch deleted via branch-indexing

Tags:

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?

like image 518
ligi Avatar asked May 13 '16 13:05

ligi


People also ask

What happens when a branch is deleted?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.

Does deleting a branch delete files?

Like all deletes in svn, the branch is never really deleted, it's just removed from the current tree.

What is orphaned item strategy Jenkins?

Orphaned Item StrategyComputed folders can remove items immediately or leave them based on a desired retention strategy. By default, items will be removed as soon as the folder computation determines they are no longer present.


2 Answers

Since you are using latest Jenkins version, consider switching your jobs to 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.

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).

like image 81
madhead - StandWithUkraine Avatar answered Sep 26 '22 01:09

madhead - StandWithUkraine


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

2) Then go to your multibranch pipeline configuration and choose JGit instead Default under Branch Sources -> Git Executable

3) Press Branch Indexing -> Run now

Old branches should go away now

like image 22
StasKolodyuk Avatar answered Sep 25 '22 01:09

StasKolodyuk