我有一个私人的GitHub Rust项目,它依赖于另一个私人的GitHub Rust项目,我想和Jenkins一起构建主要的项目。在下面的代码中,我将组织称为Organization
,并将依赖包称为subcrate
。
我的Jenkinsfile看起来像这样
pipeline {
agent {
docker {
image 'rust:latest'
}
}
stages {
stage('Build') {
steps {
sh "cargo build"
}
}
etc...
}
}
我在Cargo.toml
中尝试了以下方法来引用依赖项,它在我的机器上运行得很好
[dependencies]
subcrate = { git = "ssh://git@ssh.github.com/Organization/subcrate.git", tag = "0.1.0" }
当Jenkins运行时,我得到以下错误
+ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Updating git repository `ssh://git@github.com/Organization/subcrate.git`
error: failed to load source for a dependency on `subcrate`
Caused by:
Unable to update ssh://git@github.com/Organization/subcrate.git?tag=0.1.0#0623c097
Caused by:
failed to clone into: /usr/local/cargo/git/db/subcrate-3e391025a927594e
Caused by:
failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded
Caused by:
error authenticating: no auth sock variable; class=Ssh (23)
script returned exit code 101
如何让货物访问此GitHub存储库?是否需要将GitHub凭据注入到从机上?如果是这样,我该怎么做呢?有没有可能首先使用Jenkins用来检查主箱的相同凭证?
我安装了ssh-agent
插件并更新了我的Jenkinsfile文件,如下所示
pipeline {
agent {
docker {
image 'rust:latest'
}
}
stages {
stage('Build') {
steps {
sshagent(credentials: ['id-of-github-credentials']) {
sh "ssh -vvv -T git@github.com"
sh "cargo build"
}
}
}
etc...
}
}
我得到了错误
+ ssh -vvv -T git@github.com
No user exists for uid 113
script returned exit code 255
发布于 2018-07-24 07:32:56
好的,我知道了,No user exists for uid
错误是因为主机/etc/passwd
和容器/etc/passwd
中的用户不匹配。这可以通过安装/etc/passwd
来修复。
agent {
docker {
image 'rust:latest'
args '-v /etc/passwd:/etc/passwd'
}
}
然后
sshagent(credentials: ['id-of-github-credentials']) {
sh "cargo build"
}
工作正常
https://stackoverflow.com/questions/51441880
复制相似问题