Command not found in jenkins pipeline grrovy

2.2k views Asked by At

I'm getting a "command not found" error while executing the below jenkns code. Could someone please help me to solve this?

def myVariable = "foo"

pipeline {
    agent none
    
    stages {
        stage ('npm publish on web package') {
            agent {label 'master'}
        
            steps {
                catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                    script{
                        def pom = readMavenPom file: 'Project1/pom.xml'
                        sh "echo ${pom.version}"
                        sh 'ssh -tt [email protected] cd /opt/admin/projects/as/ && echo "${myVariable}" >/opt/automation/projects/automation_suite/.version'
                    }    
                }
            }
        }
    }
}

Log is attached below. This is the part of the log which is related to the jenkins error.

Commit message: "fff"
[Pipeline] withEnv
[Pipeline] {
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] catchError
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ 1.1.39
/opt/software/jenkins/workspace/automation_suite/Test_Pipeline_2@tmp/durable-14b3d621/script.sh: line 1: 1.1.39: command not found
[Pipeline] }
[Pipeline] // script
[Pipeline] }
ERROR: script returned exit code 127
[Pipeline] // catchError
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
1

There are 1 answers

0
Szymon Stepniak On

Double-check your pipeline code. The error you see can be caused by

sh "${pom.version}"

The example you posted uses

sh "echo ${pom.version}"

but if this was the case, you would see something like this in the console log:

[Pipeline] sh
+ echo 1.1.39
1.1.39
[Pipeline] }

Your console log proves that it is not the case and you pass ${pom.version} to the sh command somewhere clearly.

[Pipeline] sh
+ 1.1.39
/opt/software/jenkins/workspace/automation_suite/Test_Pipeline_2@tmp/durable-14b3d621/script.sh: line 1: 1.1.39: command not found