docker - ssh-add 使 Jenkins 管道作业失败
问题描述
Jenkins (2.162),更新了模块。我需要为 cargo build 添加私有 github 依赖项。所以,我需要先将 SSH 密钥存储到 Jenkins 容器中cargo build
。
我做了:
stage('Build') {
steps{
script {
dir('api'){
withCredentials([string(credentialsId: 'GitKeyText', variable: 'ID_RSA')]) {
sh '''
set +x
eval `ssh-agent -s`
mkdir ~/.ssh
echo ${ID_RSA} >~/.ssh/id_rsa
chmod go-r ~/.ssh/id_rsa
ssh-add
cargo build
'''
}
}
input message: "wait"
}
}
}
一切看起来都很好,并且这个命令序列在 docker 容器内手动运行良好。但是,Jenkins 的工作一直失败,ssh-add
没有任何错误消息。就ERROR: script returned exit code 1
在 Jenkins 控制台日志的末尾。
add01:我在代码中添加了回显注释,并更改set +x
为set -x
ssh-add
(控制台输出)没有输出
.....
+ echo before ssh-add
before ssh-add
+ ssh-add
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // script
Post stage
.....
解决方案
我使用了 Jenkins SSH 代理插件。所有工作都按预期工作。
script {
dir('contract_api'){
sshagent(['GitSSHcred']) {
sh 'cargo build'
}
}
}
推荐阅读
- sql - how to properly split a tab delimited value into individual columns in ORACLE
- javascript - jVectorMap 将 setFocus 上的地图缩放或缩放到区域代码
- sqlite - android.database.sqlite.SQLiteException: no such column error even if column exists
- amazon-web-services - Soft memory limit for AWS ECS task defined by docker-compose.yaml
- python - Remove recursively from a BST
- vue.js - MDBootstrap vue.js 模态转换不起作用
- python - 发出请求时python中的SSL认证错误
- vba - 如果添加了签名,则获取没有签名的 Outlook 电子邮件正文 (VBA)
- vba - 无法在 ServerXMLHTTP 请求中设置自定义超时
- .htaccess - 仅在主页的 url 中删除查询字符串(htaccess)