我正在尝试为jenkins在管道中使用yarn bin lerna命令,但是当它尝试用ssh凭据获取/更新包git存储库时,它失败了。
在多分支项目中使用以下Jenkinsfile。
stages {
stage('Install NPM Deps') {
steps {
configFileProvider([configFile(
fileId: 'npm-auth',
targetLocation: '.npmrc'
)]) {
withCredentials([sshUserPrivateKey(credentialsId: 'cred-id', keyFileVariable: 'KEY')]) {
withEnv(['GIT_SSH=ssh -i ${KEY} -l git']) {
script {
docker.image("node").inside("-u0 -vnode_home:/.npm") {
sh 'yarn'
sh 'yarn clean --yes'
sh 'yarn bootstrap'
sh '$(yarn bin lerna) version ${VERSION}'
//sh 'yarn test'
//sh 'yarn deploy'
}
}
}
}
}
}运行管道时出错。
+ yarn bin lerna
+ /var/jenkins/workspace/test-lib/node_modules/.bin/lerna version patch
lerna notice cli v3.22.1
lerna info versioning independent
lerna info ci enabled
lerna ERR! Error: Command failed: git remote update
lerna ERR! error: cannot run ssh -l git: No such file or directory
lerna ERR! fatal: unable to fork
lerna ERR! error: Could not fetch origin
lerna ERR!
lerna ERR! Fetching origin
lerna ERR! lerna Command failed: git remote update
lerna ERR! lerna error: cannot run ssh -l git: No such file or directory
lerna ERR! lerna fatal: unable to fork
lerna ERR! lerna error: Could not fetch origin
lerna ERR! lerna
lerna ERR! lerna Fetching origin
lerna ERR! lerna 我尝试过用键创建~/.ssh/id_rsa文件,但仍然失败。
更新:在将GIT_SSH更新为GIT_SSH_COMMAND之后,错误发生了更改。
lerna info versioning independent
lerna info ci enabled
lerna ERR! Error: Command failed: git remote update
lerna ERR! Host key verification failed.
lerna ERR! fatal: Could not read from remote repository.
lerna ERR!
lerna ERR! Please make sure you have the correct access rights
lerna ERR! and the repository exists.
lerna ERR! error: Could not fetch origin
lerna ERR!
lerna ERR! Fetching origin
lerna ERR! 我猜这是由于提示将主机添加到已知的主机文件。
更新了,以便按预期添加GIT_SSH_COMMAND=ssh -i ${KEY} -o "StrictHostKeyChecking no" -l git,解决了这个问题。
发布于 2022-05-22 04:09:27
环境变量GIT_SSH (与GIT_SSH_COMMAND不同)不能有选项。参见the main git documentation,其中部分内容如下:
GIT_SSH,GIT_SSH_COMMAND
..。
$GIT_SSH_COMMAND优先于$GIT_SSH,并由shell解释,它允许包含额外的参数。另一方面,如果需要额外的参数,$GIT_SSH只能是一个可以成为包装外壳脚本的程序的路径)。
显然,您希望在这里使用GIT_SSH_COMMAND,而不是GIT_SSH。
话虽如此,这里还有一件奇怪的事:
withEnv('GIT_SSH=ssh -i ${KEY} -l git') {
为什么-i ${KEY}不见了?
https://stackoverflow.com/questions/72331940
复制相似问题