问题描述
我想做一些类似的事情:
I'd like to do something along the lines of:
这太简单了,只是演示了我想做的事情.基本上,我希望能够在多个构建步骤之间的单个作业范围内存储和访问变量.此外,我可以通过将数据存储到文件中并稍后读取它来解决问题,但我想要一些更简单且不那么hacky"的东西
This is overly simple and just demonstrates what I'd like to do. Basically, I want to be able to store and access variables within a single job scope between multiple build steps. Also, I can get around by storing the data to a file and reading it later, but I'd like something easier and less 'hacky'
构建步骤 #1 - 执行 shell
Build Step #1 - Execute shell
$START=timestamp
构建步骤 #2 - 运行另一个作业
Build Step #2 - Run another job
构建步骤 #3 - 执行 Shell
Build Step #3 - Execute Shell
$END=timestamp
TIME_LAPSED=$END-$START
(post lapsed time somewhere)
推荐答案
shell 之间只剩下一个东西:工作空间.
简单而愚蠢的解决方案:使用文件!
One thing remains between shells: the workspace.
Simple and stupid solution: use file(s)!
巨大的额外优势:当您将工作拆分为多个工作并使用克隆工作区插件时,它会起作用
Huge additional advantage: it works when you split your job in several jobs and use the Clone Workspace plugin
构建步骤 #1 - 执行 shell
START=timestamp
...
echo $START > env_start.txt
...
构建步骤 #3 - 执行 Shell
START=`cat env_start.txt`
END=timestamp
TIME_LAPSED=$END-$START
这篇关于在 Jenkins 的构建步骤之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!