无法更改Jenkins字符串参数变量 [英] Can not change Jenkins String Parameter Variable

查看:752
本文介绍了无法更改Jenkins字符串参数变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Jenkins字符串参数$ {EMAIL_ID},用户可以在其中输入其电子邮件ID. (例如,他们输入了myid@gmai.com

I have Jenkins String Parameter ${EMAIL_ID} where user can enter their email id. (say they entered myid@gmai.com

但是在此过程的中间,我想将其更改为在以下Execute Shell中的配置中指定的某个值.

But in the middle of the process i would like to change it to some value that i specify in the configuration as below in Execute Shell .

EMAIL_ID='example@ex.com'
echo $EMAIL_ID
--returns example@ex.com

如果我在下一个Execute Shell中使用此变量 它返回myid@gmai.com

If I use this variable in next Execute Shell it returns myid@gmai.com

我需要打印example@ex.com

推荐答案

每个"执行Shell "或任何其他构建步骤都会启动一个新的独立环境.这个新环境继承了实际环境变量和为该作业定义的所有构建参数的副本,但意识到它们是副本/继承.

Each "Execute Shell" or any other build step initiates a new and separate environment. This new environment inherits a copy of actual environment variables and all build parameters that are defined for the job, but realize that they are copies/inherited.

您可以轻松更改环境变量的值:

You can change the value of an environment variable easily:

  • param = new_value(在Unix中)
  • set param = new_value(在Windows中)

但是,对于执行外壳"步骤的那个实例,该更改将本地.如果您在同一执行外壳"步骤中回显该变量,则可以看到更改,但是在下一个执行外壳"中,您将获得一个新副本(具有原始值).

However that change will be local to that instance of the "execute shell" step. You can see the change if you echo that variable within the same "execute shell" step, but in the next "execute shell", you get a new copy (with original value).

要在构建步骤之间(或在此作业之间)保留更改的变量,您需要在第一步中保存它,并在下一步中加载它.最简单的是将值输出到文件:
echo param=$param > temp.props
然后使用 EnvInject插件(请注意,您需要在现有的两个执行外壳"步骤之间配置 EnvInject 构建步骤.

To preserve your changed variable between build steps (or between jobs for that matter), you need to save it during the first step, and load it during the next. Easiest is to output the value to a file:
echo param=$param > temp.props
And then read this file into the second "execute shell" step using EnvInject plugin (note, you will need to configure EnvInject build step in between your 2 existing "execute shell" steps.

这篇关于无法更改Jenkins字符串参数变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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