所以我有一个应该播种我的DSL作业的时髦脚本,但是我不确定在获取凭据并将其分配给env var时我在做什么错:
for(job in product_base_jobs) {
pipelineJob("${job}") {
definition{
cpsScm {
scm {
git {
branches('staging')
remote {
credentials('jenkins-git')
url("git@gitty.local/${job}.git")
}
}
}
scriptPath("./Jenkinsfile")
}
triggers {
}
}
wrappers{
colorizeOutput()
timestamps()
credentialsBinding{
usernamePassword('ARTIFACTORY_USER','ARTIFACTORY_PASS','JenkinsArtifactoryCredentials')
usernamePassword('ACCESS_KEY','SECRET_KEY','Jenkins_S3')
}
}
environmentVariables{
env('ARTIFACTORY_USER',"${ARTIFACTORY_USER}")
env('ARTIFACTORY_PASS',"${ARTIFACTORY_PASS}")
env('ACCESS_KEY',"${ACCESS_KEY}")
env('SECRET_KEY',"${SECRET_KEY}")
}
}
}
我还尝试使用另一种方法未能成功:
credentialsBinding{
usernamePassword{
usernameVariable('ARTIFACTORY_USER')
passwordVariable('ARTIFACTORY_PASS')
credentialsId('JenkinsArtifactoryCredentials')
}
usernamePassword{
usernameVariable('ACCESS_KEY')
passwordVariable('SECRET_KEY')
credentialsId('Jenkins_S3')
}
}
environmentVariables{
env('ARTIFACTORY_USER',"${ARTIFACTORY_USER}")
env('ARTIFACTORY_PASS',"${ARTIFACTORY_PASS}")
env('ACCESS_KEY',"${ACCESS_KEY}")
env('SECRET_KEY',"${SECRET_KEY}")
}
}
这是我遇到的错误:
Processing DSL script jobs.groovy
Warning: (jobs.groovy, line 30) acceptMergeRequestOnSuccess is deprecated
Warning: (jobs.groovy, line 34) addNoteOnMergeRequest is deprecated
Warning: (jobs.groovy, line 35) addVoteOnMergeRequest is deprecated
Warning: (jobs.groovy, line 36) acceptMergeRequestOnSuccess is deprecated
ERROR: (jobs.groovy, line 50) No such property: ARTIFACTORY_USER for class: javaposse.jobdsl.dsl.helpers.toplevel.EnvironmentVariableContext
Finished: FAILURE
我正在处理一个错误,还是只是一种错误的方法。通常,我会将女巫用作脚本时尚的一部分,但我想整合许多具有许多共同点的作业。
管道作业类型不支持wrappers
和environmentVariables
。这些方法可用是Job DSL的一个问题,请参见Jenkins-31832。
而不是使用Job DSL添加凭据,而是在Jenkinsfile
中使用管道代码访问任何凭据。请参阅凭证绑定:
node {
withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
sh '''
set +x
curl -u $USERPASS https://private.server/ > output
'''
}
}