在我的 jenkins 管道脚本 (Jenkinsfile) 中,我正在使用 jobDsl 步骤创建 pipelineJob:s,如下所示:
pipeline {
agent any
stages {
stage('create pipelines') {
steps {
jobDsl scriptText: """
pipelineJob('myfolder/myname') {
definition {
cps {
script(readFileFromWorkspace('Jenkinsfile.subfolder')
}
}
}
"""
}
}
}
}
上面的代码运行良好,但我相信这些工作最好从 SCM 获取他们的 Jenkinsfile。
有 cpsScm
变体,但如何重用当前管道中的 scm-info 以便不必单独指定每个参数?
我想要一些类似的东西:
// ...
// Note: this does not work, sadly :)
jobDsl scriptText: """
pipelineJob('myfolder/myname') {
definition {
cpsScm = ${scm}
scriptPath('Jenkinsfile.subfolder')
}
}
"""
// ...
到目前为止,我想出了:
cpsScm {
scm {
git {
remote {
url('${scm.getRepositories()[0].getURIs()[0].toString()}')
credentials('bitbucket-jenkins')
}
branch('${env.BRANCH_NAME}')
}
}
scriptPath('${pipelineFile}')
}