在执行下面的jenkns代码时,出现“找不到命令”错误。有人可以帮我解决这个问题吗?
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 admin@20.100.300.28 cd /opt/admin/projects/as/ && echo "${myVariable}" >/opt/automation/projects/automation_suite/.version'
}
}
}
}
}
}
日志附在下面。这是日志中与詹金斯错误有关的部分。
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
答案 0 :(得分:1)
仔细检查您的管道代码。您看到的错误可能是由
引起的sh "${pom.version}"
您发布的示例使用
sh "echo ${pom.version}"
但是,在这种情况下,您会在控制台日志中看到以下内容:
[Pipeline] sh
+ echo 1.1.39
1.1.39
[Pipeline] }
您的控制台日志证明不是这种情况,您可以将${pom.version}
清楚地传递给sh
命令。
[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