Jenkins Build for Yarn Bin Lerna命令失败

发布于 2025-01-31 01:45:28 字数 2462 浏览 3 评论 0原文

我正在尝试使用jenkins的管道中的YARN bin leerna命令,但由于尝试以SSH凭据获取/更新git 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_sshgit_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解决了问题。

I'm trying to use yarn bin lerna command in pipeline for jenkins but it fails as it tries to fetch/update package git repository with ssh credentials.

Using below Jenkinsfile in multibranch project.

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'

                    }
                }
            }
        }
    }
}

Error when running pipeline.

+ 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 

I've tried creating ~/.ssh/id_rsa file out of the key but still fails.

UPDATE:
After updating GIT_SSH to GIT_SSH_COMMAND error has changed.

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! 

I'm guessing it is due to prompt of adding host to known host file.

UPDATE
So as predicted adding GIT_SSH_COMMAND=ssh -i ${KEY} -o "StrictHostKeyChecking no" -l git solved the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2025-02-07 01:45:28

环境变量git_ssh(与git_ssh_command无法选择。请参阅主说:部分git document ,该在某种程度上说:

git_sshgit_ssh_command
...
$ git_ssh_command优先于$ git_ssh,并被解释
由外壳,允许包括其他参数。
$ git_ssh另一方面必须只是程序的路径
如果其他参数是
需要)。

显然,您想使用git_ssh_command,而不是git_ssh,此处。

也就是说,这里还有其他奇怪的东西:

  withenv(['git_ssh = ssh -i $ {key} -l git']){
 

为什么-i $ {key}缺少?

The environment variable GIT_SSH (as distinct from GIT_SSH_COMMAND) cannot have options. See the main git documentation, which says in part:

GIT_SSH, GIT_SSH_COMMAND
...
$GIT_SSH_COMMAND takes precedence over $GIT_SSH, and is interpreted
by the shell, which allows additional arguments to be included.
$GIT_SSH on the other hand must be just the path to a program
which can be a wrapper shell script, if additional arguments are
needed).

Clearly you wanted to use GIT_SSH_COMMAND, not GIT_SSH, here.

That said, there's something else odd here:

withEnv(['GIT_SSH=ssh -i ${KEY} -l git']) {

Why is the -i ${KEY} missing?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文