This works for me,
my templates.dsl.groovy:
class TemplatesDSL {
static COMMON_ENVIRONMENT_VARIABLES = [
'ARTIFACTORY_CREDENTIALS': 'jenkins:XXXXXXX',
'ARTIFACTORY_LOCAL_NUGET_URL': '
http://artifactory.com:8083/artifactory/api/nuget/local_nuget',
'ARTIFACTORY_URL': '
http://artifactory.com:8083/artifactory/api/nuget',
'MSBUILD_EXE': 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe',
'NUGET_EXE': '$WORKSPACE\\_Build\\.nuget\\nuget.exe',
'XUNIT_CONSOLE_EXE': '$WORKSPACE\\xunit.runner.console.2.1.0\\tools\\xunit.console.exe'
]
static generateJob(def dslFactory,
project,
repo,
branch_simple_name,
full_branch_name,
job_name,
build_environment_variables,
nupkg_environment_variables,
properties_filename,
merge_to_branch) {
def BITBUCKET_CREDENTIALS = '
jen...@bitbucket.com'
def GIT_MERGE_TO_BRANCH = "${merge_to_branch}"
def GIT_REMOTE_URL = "
https://bitbucket.com/scm/${project}/${repo}.git"
def JENKINS_SLAVE_LABEL = 'POOL1'
def NUGET_ASSEMBLY_BRANCHES = [ 'develop_disabled', 'master_disabled' ]
def NUGET_SYMBOLS_BRANCHES = []
def JENKINS_WORKSPACE = "${project}.${repo}"
dslFactory.folder("${project}")
dslFactory.folder("${project}/${repo}")
dslFactory.folder("${project}/${repo}/${branch_simple_name}")
dslFactory.job("${project}/${repo}/${branch_simple_name}/build") {
description("This job is responsible for building the ${repo} repository")
checkoutRetryCount(3)
label(JENKINS_SLAVE_LABEL)
concurrentBuild(false)
customWorkspace(JENKINS_WORKSPACE)
scm {
git {
branch("*/${full_branch_name}")
remote {
url(GIT_REMOTE_URL)
credentials(BITBUCKET_CREDENTIALS)
}
extensions {
cleanAfterCheckout()
mergeOptions {
remote('origin')
branch(GIT_MERGE_TO_BRANCH)
}
cloneOptions {
shallow(true)
}
}
}
}
triggers {
scm('') {
ignorePostCommitHooks(false)
}
}
steps {
environmentVariables {
for (item in COMMON_ENVIRONMENT_VARIABLES) {
env(item.key, item.value)
}
for (item in build_environment_variables) {
env(item.key, item.value)
}
}
batchFile('jenkins\\pre-build.bat')
for (item in nupkg_environment_variables) {
env(item.key, item.value)
}
}
batchFile('jenkins\\build.bat')
}
wrappers {
colorizeOutput()
timestamps()
timeout {
absolute(15)
failBuild()
}
}
publishers {
archiveXUnit {
xUnitDotNET {
pattern('*.xml')
deleteOutputFiles(true)
failIfNotNew(true)
skipNoTestFiles(true)
stopProcessingIfError(true)
}
}
wsCleanup {
deleteDirectories(false)
cleanWhenFailure(false)
cleanWhenSuccess(true)
cleanWhenUnstable(false)
cleanWhenNotBuilt(false)
cleanWhenAborted(false)
failBuildWhenCleanupFails(false)
}
}
}
}
}
my jenkins.dsl file:
// slurp some methods from a common template.
// this template job needs to be executed once to allow the seed job for this
// particular project to complete correctly.
File sourceFile = new File("/var/lib/jenkins/jobs/PROJ/jobs/PROJ.jenkins.dsl.helpers/jobs/master/jobs/build/workspace/TemplatesDSL.groovy")
Class TemplatesDSL = new GroovyClassLoader(getClass().getClassLoader()).parseClass(sourceFile)
def BUILD_ENVIRONMENT_VARIABLES = [
'CONFIGURATION': 'release'
]
def NUPKG_ENVIRONMENT_VARIABLES = [
'MY_NUPKG': 'asdfk.nupkg',
]
TemplatesDSL.generateJob(
this,
"${_injected_var_PROJECT}",
"${_injected_var_REPO}",
"${_injected_var_BRANCH_SIMPLE_NAME}",
"${_injected_var_BRANCH}",
"build",
BUILD_ENVIRONMENT_VARIABLES,
NUPKG_ENVIRONMENT_VARIABLES,
"build.properties",
"develop"
)