jenkins - 在 Jenkins 管道中不起作用凭证
问题描述
我(method: username and password)
在 Jenkins 中使用 name创建了凭据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
在哪里,我有错误。我正在根据工作示例和文档做所有事情。但我不明白,为什么它不起作用。
解决方案
查看 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}"
'''
}
}
}
}
}
推荐阅读
- mysql - 防止 MySQL 自动为外键创建索引?
- python - 使用 BeautifulSoup 解析 h1 标签下的表并存储在 df
- leaflet - React Leaflet 创建多个地图
- assembly - 如何在没有可用操作系统的情况下获取硬件信息
- webstorm - WebStorm HTML - 当对象“打印机”的类型未知时,推断 Prettier 的“打印机”类型
- c++ - 如何在VS中的终端输出末尾删除“%”
- c++ - 搜索使用对应值稍后用于排序的键时的最佳复杂度
- java - 为随机二维 java 数组问题创建用户输入 - OutOfBoundsException
- html - 在 VScode 中,当我使用快捷键 Ctrl + / 在 HTML 文件中进行注释时,它不能像这样 "{{! }}"
- android - 从 GitLab 读取 build.gradle 上的环境变量