Jenkins delete jobs when branch deleted via branch-indexing
Asked Answered
K

2

30

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?

Karriekarry answered 13/5, 2016 at 13:3 Comment(0)
K
24

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

Karns answered 13/5, 2016 at 15:45 Comment(7)
So I will consider it a bug as I am using the multibranch pipeline setup - thanksKarriekarry
I'm seeing the same thing...the old branches aren't deleted from Jenkins when they're gone from the repository. @ligi: did you file a bug?Lossa
Note that he current version of the Multibranch PIPELINE Plugin has a setting for deleted branches (and merged PR's) under "Orphaned Item Strategy" which offers a different policy than for the branches that are still active. I believe this would be the correct answer as of today.Mindexpanding
I am fighting this also, I though it was working, on the UI the pruned branches are no longer there, but on the disk the jobs are still there, the disk usage keep climbing. I can't get jenkins to automatically delete the items from diskTuckie
This is still a major issue.Batsman
Any news on this as of today?Ganny
I had this problem and it was due to no Scan Multibranch Pipeline Triggers being set, as described in issues.jenkins.io/browse/JENKINS-66970Innutrition
I
6

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

Irresolvable answered 23/3, 2017 at 13:20 Comment(1)
Where is Branch Indexing -> Run now ?Kerbstone

© 2022 - 2024 — McMap. All rights reserved.