Jenkins multibranch pipeline won't prune deleted branches
Asked Answered
H

1

39

We're currently having some trouble with the bitbucket branch source plugin used to handle a multibranch test job in one of our Jenkins instances (productive instance):

Any job related to a deleted branch is not getting deleted in Jenkins. Is is shown as disabled.

Checking the Scan Multibranch Pipeline Log I find the following entries:

Will not remove foobranch because it is new
Will not remove PR-1 because it is new
Will not remove bar because it is new
Will not remove freeDiskSpaceHack because it is new

We have another instance (test instance) where everything is working as expected - branches get removed immediately, e.g. seeing the following in the log:

Will remove freeDiskSpaceHack
Will remove foo
  • For both instances we're using the same Jenkins version (2.212.2) and plugin versions.
  • The jobs in both instances use the same settings for the Bitbucket branch source plugin:

Branch source plugin settings

  • There's one difference: Both jobs use a different repository in bitbucket; the onee of our test instance (where jobs get deleted) is a fork of the other one.

Besides that there's no difference.

My questions are:

  • Why doesn't it work for our productive instance? Is there some secret setting?
  • What does the log want to tell me saying: Will not remove <branch> because it is new.

Hopefully anyone has a clue.

Hambley answered 7/8, 2018 at 19:38 Comment(2)
I am seeing the same behaviour with a multibranch pipeline job connected to GitHub enterprise. I had put it down to a bug with multibranch pipeline.Monde
Thanks for the comment. Did you file that bug?Hambley
H
76

Finally I found the hidded switch by myself. Feeling little bit stupid, though.

In the job configuration you can specify for how long to keep old items. When setting up this job initially I must have mixed up this setting with the setting which tells jenkins for how long to keep old builds. So it was set to 30 days.

Btw.: The number of builds kept for the individual branches are not affected by this setting...:

Orphaned Item Strategy (how it looked like)

enter image description here

Orphaned Item Strategy (how it should have looked like)

However to immeditaly get rid of orphaned branches one must not enter a number there, like:

enter image description here

Hambley answered 8/8, 2018 at 16:19 Comment(5)
Both the images look the same.Lyontine
You’re right, thanks for pointing that out. Have to fix that.Hambley
What if I want to remove Job branches that are deleted from the repository and at the same time, I want to keep some number of builds for the active Job branches. Let's say: For active branches I want to keep the last 10 builds, this will never delete a removed branches from the Job if they only run twice. I'm explain?Chromous
The number of builds kept for one branch is a different setting and does not relate to this setting. It has to be configured using the properties step. You may want to check the properties step for that very purpose.Hambley
This solution wasn't sufficient for me. After selecting it, I had to go to "Manage Jenkins" -> "Reload Configuration from Disk". Once I did that, the next scan of my pipeline dropped all the old branches. Thanks!Washboard

© 2022 - 2024 — McMap. All rights reserved.