如何使用 Jenkins 参数化构建? [英] How to use Jenkins parameterized builds?

查看:38
本文介绍了如何使用 Jenkins 参数化构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins 允许您参数化构建,但我不知道如何实际使用它:

Jenkins allows you to parameterize builds, but I can't figure out how to actually make use of it:

假设我通常会像这样从命令行启动 Ant 构建:

Say I would normally kick my Ant build off from the command-line like so:

ant -buildfile /path/to/my/build.xml -DpackageType=jar package

这将调用 build.xmlpackage 目标,并使名为 packageType 的属性对其可用,其值为jar.

This would invoke the build.xml's package target, and make a property named packageType available to it, with a value of jar.

我假设在上面的屏幕截图中,Name 字段是我指定packageType 的地方,但是值呢?

I'm assuming that in the screenshot above, the Name field is where I would specify packageType, but what about the value?

  1. 如果 Jenkins 希望我为该属性指定一个默认值,那么我应该在哪里指定我的项目正在使用的值?例如,我可能需要 war默认值,但是让这个 Jenkins 作业传入 jar 的值(以覆盖默认值).
  2. 此外,Jenkins 的意思是...允许用户保存输入的实际值."哪个用户?无论如何,您会在哪里输入值?
  1. If Jenkins wants me to specify a Default Value for the property, then where do I specify the value that my project is using? For instance, I might want a Default Value of war, but have this Jenkins job pass in a value of jar (to override the default).
  2. Also, what does Jenkins mean by "...allows the user to save typing the actual value." Which user? Where would you type the value anyways?

提前致谢!

推荐答案

每当用户在 Jenkins 中配置参数化构建时,参数名称都会作为环境变量

Whenever the user configures a parameterised build in Jenkins, the parameter name is taken as an environment variable

用户可以使用环境变量来使用这些参数.

The user can make use of such parameters using the environment variable.

例如,在您的情况下,如果 packageType 是您要传递的参数,

For example, in your case if packageType is the parameter you want to pass,

然后将名称指定为 packageType 并将值指定为 war

then specify the name as packageType and value as war

您可以在您需要的脚本中使用它作为 %packageType%(对于 Batch)或 $packageType>(用于外壳)

You can use it in the script you required as %packageType% (for Batch) or $packageType (for shell)

配置好job后,无论何时点击build now按钮,Jenkins都会提示输入参数

After configuring the job, whenever you click the build now button, Jenkins prompts for the parameter

当你使用file参数时,上传的文件会被放到工作目录中

When you are using file Parameter, the uploaded file will be placed into the working directory

这篇关于如何使用 Jenkins 参数化构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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