Jenkins:在两次作业运行之间存储变量的好方法是什么?
我有一个时间触发的作业,需要检索该作业先前运行中存储的某些值。
有没有办法在 Jenkins 环境中的作业运行之间存储值?
例如,我可以在 shell 脚本操作中编写类似 next 的内容:
XXX=`cat /hardcoded/path/xxx`
#job itself
echo NEW_XXX > /hardcoded/path/xxx
但是有更可靠的方法吗?
I have a time-triggered job which needs to retrieve certain values stored in a previous run of this job.
Is there a way to store values between job runs in the Jenkins environment?
E.g., I can write something like next in a shell script action:
XXX=`cat /hardcoded/path/xxx`
#job itself
echo NEW_XXX > /hardcoded/path/xxx
But is there a more reliable approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
几个选项:
userContent
子目录,您可以使用它 - 这样该文件至少是 jenkins 安装的一部分,因此更容易迁移或备份。我为我的构建的(相当大的)代码覆盖率趋势文件执行此操作。适当的解决方案将取决于您的情况。
A few options:
userContent
subdirectory you could use for this - that way the file is at least part of the jenkins install and thus more easily migrated or backed up. I do this for the (rather large) code coverage trend files for my builds.The appropriate solution will depend on your situation.
如果您使用 Pipelines 并且变量是简单类型,您可以使用参数在同一作业的运行之间存储它。
使用
properties
步骤,您可以在管道内配置参数及其默认值。配置完成后,您可以在每次运行开始时读取它们,并在结束时保存它们(作为默认值)。在声明性管道中,它可能看起来像这样:If you are using Pipelines and you're variable is of a simple type, you can use a parameter to store it between runs of the same job.
Using the
properties
step, you can configure parameters and their default values from within the pipeline. Once configured you can read them at the start of each run and save them (as default value) at the end. In the declarative pipeline it could look something like this:我会将变量从第一个作业传递到第二个作业,作为参数化 参数化构建。有关如何触发的详细信息,请参阅此问题来自另一个构建的参数化构建。
I would pass the variable from the first job to the second as a parameter in a parameterized build. See this question for more info on how to trigger a parameterized build from another build.