I'm new to Jenkins and I'm trying to figure something out.
Is there a way to add Branch Sources behavior via Groovy. This is to analyse GitHub projects in SonarQube using Jenkins.
I'm creating a multi-branch pipeline but can't seem to figure out how to add the following behaviours.
These behaviours come by default when the job is created in the UI, but don't appear when the job is created via Groovy.
I've defined this as my pipeline. Any idea how these other parameters can be added in?
multibranchPipelineJob('Foo') {
displayName('Foo')
description('Jenkins')
branchSources {
branchSource {
source {
github {
id('15')
repoOwner('12345')
repository('foo')
repositoryUrl('https://example.com')
configuredByUrl(true)
credentialsId('foo')
traits {
gitBranchDiscovery()
}
}
}
}
}
orphanedItemStrategy {
discardOldItems {
numToKeep(10)
}
}
}
I've tried adding in the following parameters but it throws an error.
import jenkins.plugins.git.traits.*
def traits = []
traits.add(new TagDiscoveryTrait())
traits.add(new LocalBranchTrait())
gitSCMSource.setTraits(traits)
Is there a way to create the job via Groovy but with the default settings that would appear when the job is created in the UI?