Jenkins:从另一个项目复制工件时,如何使用用户定义的shell变量 [英] Jenkins: How to use user defined shell variables when copying artifacts from another project

查看:321
本文介绍了Jenkins:从另一个项目复制工件时,如何使用用户定义的shell变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Jenkins配置中,我有一个条件步骤,可导出名为"SUFFIX"的自定义外壳变量.我想在要从中复制工件的项目的名称中使用此变量,但是它说:

In my Jenkins configuration I have a conditional step which exports a custom shell variable called "SUFFIX". I want to use this variable in name the of the project from which I am copying artifacts but it says:

Unable to find project for artifact copy: myProject${SUFFIX}_release

在项目名称取决于作业参数的情况下,如何使用此类变量或实现此类行为. job参数是一个布尔值,应保持为布尔值.不应有字符串参数SUFFIX.

How can I use such a variable or achieve such a behaviour where the project name depends on a job parameter. The job parameter is a boolean value and should stay a boolean value. There should not be a string parameter SUFFIX.

此问题是否与以下问题相关:在复制时要聪明Jenkins和多种配置的人工制品 我是否需要EnvInject插件才能使复制工件插件可以访问变量?

Is this question related: Being clever when copying artifacts with Jenkins and multi-configurations Do I need the EnvInject plugin to make variables accessible by the Copying artifacts plugin?

推荐答案

Jenkins不会在构建或构建步骤之间保留环境变量的更改.这是设计的一部分,目的是保持构建环境的清洁.

Jenkins does not retain environment variable changes between builds or build-steps. This is part of the design, to keep the build environment clean.

您不能在 Execute Shell 构建步骤中导出环境变量,然后在 Copy Artifacts 构建步骤中使用它.要解决此问题,您确实需要 EnvInject插件 .

You cannot export an environment variable in Execute Shell build step, and then use it in Copy Artifacts build step. To get around this, you do need EnvInject plugin.

  • 您无需将外壳环境变量导出到环境中,而是需要将其以格式param=value
  • 写入-属性文件中.
  • 然后,使用EnvInject构建步骤,加载该属性文件
  • 之后,新加载的环境变量将可用于所有后续的构建/构建后步骤,包括复制工件"构建步骤.
  • Instead of exporting your shell environment variable to the Environment, you need to write it to - properties file, in format param=value
  • Then, using EnvInject build step, load that properties file
  • After that, your newly loaded environment variable will be available to all subsequent build/post-build steps, including Copy Artifacts build step.

这篇关于Jenkins:从另一个项目复制工件时,如何使用用户定义的shell变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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