Jenkins + Build Flow,如何将变量从一项工作传递到另一项工作 [英] Jenkins + Build Flow, how to pass a variable from one job to another

查看:152
本文介绍了Jenkins + Build Flow,如何将变量从一项工作传递到另一项工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的构建流程方案类似于文档示例:两个作业,一个接一个运行.

I have a build flow scenario similar to the documentation example: two jobs, one running after the other.

b = build("job1")
build("job2", param1: b.????)

我的job1是一个shell脚本,可以从检出的git存储库中构建一个程序包,并打印出所构建程序包的版本.

My job1 is a shell script that builds a package out of a checked out git repositoy and prints out the version of the built package.

我需要从job1中提取版本(解析输出?),并以某种方式将其用作job2的参数.如何做到这一点?请注意,在运行job1之前,我不知道版本.

I need to extract the version from job1 (parse output??) and make it available somehow as a parameter to job2. How can this be achieved? Please note that I can't know the version before running job1.

推荐答案

在shell脚本构建步骤中仅使用export的问题是,当shell脚本退出时,导出的变量消失,它们不会传播到最大.工作.

The problem with simply using export in a shell script build step is that the exported variables disappear when the shell script exits, they are not propagated up to the job.

使用 EnvInject插件在您的版本中创建环境变量.如果你 在构建过程中写出一个属性文件,EnvInject可以读取该文件,然后将变量作为构建步骤.属性文件具有简单的KEY=VALUE格式:

Use the EnvInject plugin to create environment variables in your build. If you write out a properties file as part of your build, EnvInject can read the file and inject variables as a build step. A properties file has a simple KEY=VALUE format:

MY_BUILD_VERSION=some_parsed_value

一旦在工作中设置了环境变量,就在构建流程中 插件,您可以提取变量的值并将其用于后续作业:

Once you have an environment variable set in your job, in the Build Flow plugin, you can extract the variable's value and use it in subsequent jobs:

def version = build.environment.get( "MY_BUILD_VERSION" )
out.println String.format("Parameters: version: %s", version)
build( "My Second Build", MY_BUILD_VERSION: version )

这篇关于Jenkins + Build Flow,如何将变量从一项工作传递到另一项工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆