bash Jenkins 条件步骤未完成 shell 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23958315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:34:48  来源:igfitidea点击:

Jenkins Conditional steps not completing shell script

bashjenkinsconditional

提问by Andy G

OK, so I've been asked to allow a "safe word" in our Git commit comments so that our CI build will skip if the developer wants to just commit without building. So, I set up a Conditional Step (multiple) with Execute shell in the Run? field. I'm running the following command to see if the safe word is in the commit message and if it is, "Don't run" the build and if it's not, to run the build. If I put a header in this shell (i.e. #!/bin/bash), I get an error. Without it, my script stops after setting the RUN variable. The IF..THEN..ELSE loop doesn't even begin to run. Here's my script..

好的,所以我被要求在我们的 Git 提交注释中允许一个“安全词”,以便我们的 CI 构建将跳过,如果开发人员只想提交而不构建。那么,我在运行中使用 Execute shell 设置了一个条件步骤(多个)?场地。我正在运行以下命令以查看安全词是否在提交消息中,如果是,“不要运行”构建,如果不是,则运行构建。如果我在这个 shell 中放置一个头文件(即 #!/bin/bash),我会得到一个错误。没有它,我的脚本在设置 RUN 变量后停止。IF..THEN..ELSE 循环甚至没有开始运行。这是我的脚本..

RUN=$(git --no-pager log -1 --pretty=online:"%s" --grep "keyword")
if [ "$RUN" != "" ];
    then exit 0
else
    exit 666
fi

The output when the "safe word" is not present looks like this:

不存在“安全词”时的输出如下所示:

++ git --no-pager log -1 --pretty=online:%s --grep blech
+ RUN=
Run condition [Execute Shell] preventing perform for step [BuilderChain]
Finished: SUCCESS

With the "safe word" present, the output is this:

有了“安全词”,输出是这样的:

++ git --no-pager log -1 --pretty=online:%s --grep initializer
+ RUN='online:CVirtualBroker  - Tweak construction to use initializer lists - 
Run condition [Execute Shell] preventing perform for step [BuilderChain]
Finished: SUCCESS

Notice that the RUN variable gets set, then the script stops. What gives?

请注意,设置了 RUN 变量,然后脚本停止。是什么赋予了?

AJ

AJ

回答by aorfevre

you have a semicolon at the end of If statement

If 语句的末尾有一个分号

if [ "$RUN" != "" ];

if [ "$RUN" != "" ];

which make it stop...

这使它停止......

The command after is exit 0so I assume that your process stops

之后的命令是exit 0所以我假设你的进程停止了