简体   繁体   English

当 shell 脚本的 grep 命令失败时,Jenkins 管道退出

[英]Jenkins Pipeline exiting when grep command of shell script fails

I have a Jenkinsfile written for Scripted Pipeline where I have the following piece of code:我有一个为 Scripted Pipeline 编写的 Jenkinsfile,其中有以下代码:

sh """ cd $WORRKSPACE
       source myscript.sh
       cd \${EXPORTED_VAR1}
       .
       .
       .
"""

So I source myscript which in turn has a source command in it, say source their_script.sh .所以我 source myscript 里面有一个 source 命令,比如source their_script.sh The problem is like their_script.sh contains a line echo $0 | egrep -iqe string问题就像 their_script.sh 包含一行echo $0 | egrep -iqe string echo $0 | egrep -iqe string . echo $0 | egrep -iqe string And whenever egrep finds no match my Jenkins job exits.每当 egrep 找不到匹配项时,我的 Jenkins 作业就会退出。 But this happened suddenly and it was working till yesterday!!!但这突然发生了,它一直工作到昨天!

I understand that grep returns status 1 when it finds no match and that is why it exits.我知道 grep 在找不到匹配项时返回状态 1,这就是它退出的原因。 But I wanted myscript to continue even if grep failed.但即使 grep 失败,我也希望 myscript 继续。 I also understand that using set +e and set -e will help me not to exit if grep fails.我也明白,如果 grep 失败,使用set +eset -e将帮助我不退出。 But I am not allowed to modify their_script.sh.但我不允许修改 their_script.sh。 If I add set +/-e when I call myscript itself, will the case be like none of the errors will exit the script?如果我在调用 myscript 本身时添加set +/-e ,情况是否会像没有错误会退出脚本一样? Wont it ignore all errors from exiting?它不会忽略退出的所有错误吗?

Is there any solution so that I can continue with my job even if grep fails?即使 grep 失败,是否有任何解决方案可以让我继续工作?

Try尝试

sh """#!/bin/bash -xe
cd ${WORKSPACE}
## etc.
...
"""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM