首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jenkins生成纱bin lerna命令失败

Jenkins生成纱bin lerna命令失败
EN

Stack Overflow用户
提问于 2022-05-21 17:45:09
回答 1查看 445关注 0票数 0

我正在尝试为jenkins在管道中使用yarn bin lerna命令,但是当它尝试用ssh凭据获取/更新包git存储库时,它失败了。

在多分支项目中使用以下Jenkinsfile。

代码语言:javascript
复制
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'

                    }
                }
            }
        }
    }
}

运行管道时出错。

代码语言:javascript
复制
+ 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之后,错误发生了更改。

代码语言:javascript
复制
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,解决了这个问题。

EN

回答 1

Stack Overflow用户

发布于 2022-05-22 04:09:27

环境变量GIT_SSH (与GIT_SSH_COMMAND不同)不能有选项。参见the main git documentation,其中部分内容如下:

GIT_SSHGIT_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}不见了?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72331940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档