如何使用命令的结果来决定詹金斯阶段是否应该执行?
我有一个非常简单的声明性詹金斯文件,该文件使用curl从API检索配置文件,然后使用diff命令查看它们是否与存储库中的同一配置文件不同。如果检索配置文件不同,我想替换旧文件并提交新文件。
我似乎无法弄清楚如何存储一个值(例如$ config_changed = yes)并在下一阶段/步骤中使用它。理想情况下,如果不更改配置,我想跳过几个阶段,但是我不知道如何在整个管道上重复使用变量。我已经搜索了很多谷歌,但是似乎环境变量是不变的,并且在管道中无法更改。也许有一种非常简单的方法我没有看到?我将感谢一些朝着正确方向的指示。
I have a very simple declarative Jenkins file which uses cURL to retrieve config files from an API and then uses the diff command to see if they are different from the same config files in the repository. If the retrieves config files are different, I would like to replace the old files and commit the new ones.
I can't seem to figure out how to store a value (for example $CONFIG_CHANGED = YES) and use it in the next stage/step. Ideally I would like to skip a couple of stages if the config is not changed, but I don't know how to re-use variables across the pipeline. I have googled quite a bit but it seems that environment variables are immutable and can't be changed in the pipeline. Maybe there is a really simple approach to this that I am not seeing? I would appreciate some pointers in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一部分将说明如何在Shell脚本中提取设置的值。然后,我将解释如何有条件运行一个阶段。
以下是可以从外壳执行中提取值的几种方法。
提取值后,您可以定义一个新阶段,并在{}时添加条件检查。以下是完整的管道。
The first part will explain how to extract the value set in the shell script. Then I'll explain how to conditionally run a stage.
Here are a few ways you can extract the value from shell execution.
After extracting the value you can define a new stage and add a conditional check with when{}. Following is the full Pipeline.