'Jenkins build fails for yarn bin lerna command

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.



Solution 1:[1]

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?

Solution 2:[2]

The compiler is clearly explaining the issue: it can't find identifier minmax. The reason it can't be found is because by the time iswin is defined minmax isn't declared. In the code minmax is declared(and defined) after it is used, thus, the compiler can't find the identifier. In order to fix it just declare it anywhere before iswin definition using:

int minimax(char cb[],int max);

You can read more about it in the following pages: microsoft, myprogrammingnotes.

If it is a matter of fundaments better grab a good book.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 torek
Solution 2 Baltasar del Sol de Haro