场景:我无法在后期步骤中传递参数。下面是错误 post {Script{ sh“count=
ca changes.txt | wc -lecho ${count}如果[ ${count} == 0 ];然后回显‘条件成功’否则回送‘条件而不是成功’fi”“}‘}’
错误:
16:24:38 email-2运行shell脚本16:24:39 ++ cat changes.txt 16:24:39 ++ wc -l 16:24:39 + count=7管道}管道/脚本错误执行成功后条件: groovy.lang.MissingPropertyException: No此类属性:$count表示类: WorkflowScript at org.codehaus。groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
发布于 2019-12-09 20:38:42
这应该是可行的:
pipeline {
agent any
stages {
stage ('test') {
steps {
script {
sh """
echo "1" > changes.txt
count=\$(cat changes.txt | wc -l)
echo \$count
if [ \$count = 0 ]; then
echo 'condition success'
else
echo 'condition not success'
fi
"""
}
}
}
}
}输出:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on jenkins in /home/user/workspace/test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (test)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ echo 1
+ cat changes.txt
+ wc -l
+ count=1
+ echo 1
1
+ [ 1 = 0 ]
+ echo condition not success
condition not success
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS https://stackoverflow.com/questions/59251635
复制相似问题