我已经在詹金斯(Jenkins)中创建了名为(method: username and password)
的凭据wwe_hello
。
为了进行测试,我创建了名称为test
的管道:
pipeline {
agent {label 'slave1'}
environment {
CREDS = credentials("wwe_hello")
}
stages {
stage('WWE') {
steps {
sh 'echo "$CREDS"'
}
}
}
}
结果我有:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on slave1 in /var/lib/jenkins/workspace/test
[Pipeline] {
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: wwe_hello
Finished: FAILURE
在哪里,我有错误。我正在根据工作示例和文档进行所有操作。但是我不明白,为什么它不起作用。
答案 0 :(得分:2)
查看withCredentials的管道步骤文档。您无需使用env创建环境变量-withCredentials会为您完成此操作:
pipeline {
agent any
stages {
stage('only') {
steps {
withCredentials([
usernamePassword(
credentialsId: 'CRED',
usernameVariable: 'USER',
passwordVariable: 'PASS'
)]) {
sh '''
echo "The username is: ${USER}"
echo "The password is : ${PASS}"
'''
}
}
}
}
}