0
votes

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
You know that sh "${myVariable}" => sh "foo" ? Is foo a valid command?Szymon Stepniak
sorry for that. i'ts my mistake when adding the question. it was not there in the code.ShanWave007
Now, i've re-corrected the codeShanWave007
Add a full console log as well. command not found does not leave any clue about which command may cause the issue.Szymon Stepniak
Added the log partShanWave007

1 Answers

1
votes

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