Hi all,
My multibranch setup is working fine, but the only problematic thing is that Jenkins deletes the pipeline for a deleted branch only during the next scan. Interestingly, Jenkins immediately detects when a branch is deleted, because Bitbucket calls Jenkins’ webhook. At that point, Jenkins marks the pipeline as disabled — but does not delete it.
It’s important for us to have these branch pipelines deleted promptly, as they consume unnecessary disk space and slightly degrade the user experience. I don’t want to use frequent scanning, since it’s a heavy process.
From what I’ve read online, this seems to be the default behavior of Jenkins. Does anyone know why Jenkins designed this feature like this? While this could be a reasonable default, there should ideally be a way to delete the pipeline for a deleted branch immediately.
Below is the DSL script of my pipeline:
multibranchPipelineJob(v.getName() + ' Multibranch') {
displayName(v.getName() + ' Multibranch')
branchSources {
branchSource {
source {
bitbucket {
id = "pipeline-build"
credentialsId("Jenkins-Ci-BitBucket-Credentials")
repoOwner("my-company")
repository(k)
serverUrl("https://bitbucket.org")
traits {
bitbucketBranchDiscovery {
strategyId(1)
}
bitbucketPullRequestDiscovery {
strategyId(1)
}
refSpecs {
templates {
refSpecTemplate {
value ('+refs/heads/*:refs/remotes/@{remote}/*')
}
}
}
}
}
}
strategy {
allBranchesSame {
props {
suppressAutomaticTriggering {
strategy('INDEXING')
triggeredBranchesRegex('^.*$')
}
}
}
}
}
}
orphanedItemStrategy {
defaultOrphanedItemStrategy {
pruneDeadBranches(true)
daysToKeepStr("0")
numToKeepStr("0")
abortBuilds(true)
discardOldItems {
numToKeep(0)
}
}
}
}
}
Jenkins setup:
Jenkins: 2.509
OS: Linux - 5.10.237-230.949.amzn2.x86_64
Java: 21.0.7 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)