I've been trying to populate the RefSpec template on the GitSCM source, but I cannot seem to get it to work. I've failed to find any examples of how to do it.
Does anyone have an idea how to use it?
package utils
import groovy.transform.builder.Builder
import groovy.transform.builder.SimpleStrategy
import javaposse.jobdsl.dsl.DslFactory
import javaposse.jobdsl.dsl.Job
import javaposse.jobdsl.dsl.jobs.MultibranchWorkflowJob
// Created to make it easy to creade new jobs without duplicating the code
@Builder(builderStrategy = SimpleStrategy, prefix = '')
class GithubPipeline {
String viewPrefix
String repository
String jobSuffix = ""
String includes = "*"String jenkinsfileLocation = "Jenkinsfile"Boolean discoverBranches = trueBoolean discoverTags = trueBoolean includeMasterRef = false
MultibranchWorkflowJob build(DslFactory dslFactory) {
def cleanedRepoString = this.repository.toLowerCase().replaceAll(/_/, '-');
def jobId = "${this.viewPrefix.toLowerCase()}-${cleanedRepoString}"if (this.jobSuffix) jobId += "-${jobSuffix}"
dslFactory.multibranchPipelineJob(jobId) {
branchSources {
github {
id(jobId)
includes(this.includes)
repoOwner('comp')
repository(this.repository)
scanCredentialsId('github-appscicomp-dev-token')
checkoutCredentialsId('github-appscicomp-dev-token')
}
}
factory {
workflowBranchProjectFactory {
scriptPath(this.jenkinsfileLocation)
}
}
configure {
def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
if (this.discoverBranches) {
traits << 'org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait' {
strategyId(3) // detect all branches -refer the plugin source code for various options
}
}
if (this.discoverTags) {
traits << 'org.jenkinsci.plugins.github_branch_source.TagDiscoveryTrait' { }
}
if (this.includeMasterRef) {
traits << 'jenkins.plugins.git.traits.RefSpecsSCMSourceTrait' {
tempates << 'jenkins.plugins.git.traits.RefSpecsSCMSourceTrait$RefSpecTemplate' {
value('+refs/heads/master:refs/remotes/@{remote}/master')
}
}
}
}
orphanedItemStrategy {
discardOldItems {
daysToKeep(20)
numToKeep(25)
}
}
}
}
}
I've been trying to populate the RefSpec template on the GitSCM source, but I cannot seem to get it to work. I've failed to find any examples of how to do it.
Or use the following configure block. Make sure to use the correct element names. Configure the job manually and use the element names from that config.