Advanced clone behavior caused all branches to build

144 views
Skip to first unread message

Sverre Moe

unread,
Jun 13, 2018, 7:53:56 AM6/13/18
to Jenkins Users
Adding Branch Source "Advanced clone behaviors" caused Jenkins to initiate build of ALL my branches.
All I wanted was to make sure the git tags where fetched during checkout.

Takeover for application » master by source #1 from source that no longer exists
Branch reopened: master (ae0617dc2ceea28577b4c73356f705f2d597ae6c)

The branch was never "closed".

After saving the project it performed a Multibranch Pipeline scan. Then it started building almost 300 branches.
It took forever to cancel all those builds.
I ultimately had to remove the advanced clone behavior. Then just add a simple sh "git fetch  --tags --quiet" to my pipeline script.


Desperately need an Kill All jobs in Jenkins. Having 2-300 jobs suddenly triggered is a nightmare.
And because Jenkins will NOT kill the job immediately I need to click like a maniac several times on cancel.
When I mean kill, I mean kill, the consequences be damned.

Sverre Moe

unread,
Jun 13, 2018, 8:51:22 AM6/13/18
to Jenkins Users
I am not sure if it was the advanced clone behavior that causes this.
Another project that got triggered by notifyCommit URL just started to build ALL branches.

The only other change I have done was to add Discover Tags.

Perhaps it is the way I did it?
I deleted the existing Branch Source and created a new one.
Perhaps that is Why it is rebuilding all branches?

However, if I scan again, it will trigger all branches again. Every time.

import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
 
import hudson.plugins.git.browser.GitWeb
import hudson.plugins.git.extensions.impl.CloneOption
import jenkins.branch.BranchSource
import jenkins.branch.DefaultBranchPropertyStrategy
import jenkins.plugins.git.GitSCMSource
import jenkins.plugins.git.traits.BranchDiscoveryTrait
import jenkins.plugins.git.traits.CloneOptionTrait
import jenkins.plugins.git.traits.TagDiscoveryTrait
 
 
def jenkinsInstance = jenkins.model.Jenkins.getInstance()
jenkinsInstance
.getView("projects").getItems().each { project ->
   
if (project instanceof WorkflowMultiBranchProject) {
       
def sources = project.getSourcesList()
        sources
.clear()
 
       
def projectName = project.getName()
       
def REMOTE = "ssh://g...@git.company.com/projects/"+ projectName +".git"
       
GitSCMSource gitSCMSource = new GitSCMSource(null, REMOTE, "c9atdnbtdy1883", "*", "", false)
       
DefaultBranchPropertyStrategy strategy = new DefaultBranchPropertyStrategy(null)
 
       
def url = "http://git.company.com/gitweb/?p=projects/"+projectName+".git"
       
def browser = new GitWeb(url)
        gitSCMSource
.setBrowser(browser)
 
       
def traits = new ArrayList()
 
       
def branchTrait = new BranchDiscoveryTrait()
        traits
.add(branchTrait)
 
       
def tagTrait = new TagDiscoveryTrait()
        traits
.add(tagTrait)
 
       
def cloneOption = new CloneOption(false, false, "", null)
        cloneOption
.setDepth(0)
       
def cloneOptionTrait = new CloneOptionTrait(cloneOption)
        traits
.add(cloneOptionTrait)
 
        gitSCMSource
.setTraits(traits)
 
       
BranchSource branchSource = new BranchSource(gitSCMSource, strategy)
        sources
.add(branchSource)
   
}
}


Sverre Moe

unread,
Jun 13, 2018, 9:21:34 AM6/13/18
to Jenkins Users
It seems more evident now that the reason for all branches gotten triggered was that I scratched the Branch Source configuration and created a new one.
After I let all the branches build (fail and succeed) then scanning again would not trigger a second run.
Reply all
Reply to author
Forward
0 new messages