【问题标题】:Override environment variable created locally in Jenkins覆盖在 Jenkins 本地创建的环境变量
【发布时间】:2016-10-30 20:05:49
【问题描述】:

我有 2 个属性文件,我希望通过邮件发送它们的内容。我的做法是这样的:

  1. EnvInject读取这些文件

  1. 使用这些变量来发送 via 邮件:

那些配置文件包含不同的链接和日期,我在电子邮件中看到相同的输出:

Android Mobile Client Release Notes CH

Link: ftp://testlink_CH
Date: 28/06/2016

Android Mobile Client Release Notes PL

Link: ftp://testlink_CH
Date: 28/06/2016

当 ${Link} 被设置时,即使我尝试“unset”命令,它也不会被忽略。

[EnvInject] - Injecting environment variables from a build step.
[EnvInject] - Injecting as environment variables the properties file path 'AndroidDev/CH/config.properties'
[EnvInject] - Variables injected successfully.
[EnvInject] - Injecting as environment variables the properties content 
LINK_CH=${Link}
DATE_CH=${Date}

[EnvInject] - Variables injected successfully.
[mvandroid] $ /bin/sh -xe /tmp/hudson108948632979693109.sh
+ unset Link
+ unset Date
[EnvInject] - Injecting environment variables from a build step.
[EnvInject] - Injecting as environment variables the properties file path 'AndroidDev/PL/config.properties'
[EnvInject] - Variables injected successfully.
[EnvInject] - Injecting as environment variables the properties content 
LINK_PL=ftp://testlink_CH
DATE_PL=28/06/2016

你能帮我解决这个问题吗?或者给我你煽动这个?

【问题讨论】:

  • 您无法取消设置系统环境变量。您只能删除继承的环境变量。
  • 您能详细说明一下吗?我对此比较陌生...我正在设置系统环境变量?什么是继承的环境变量?

标签: jenkins environment-variables


【解决方案1】:

发生这种情况的原因在于 env-inject 插件的工作方式。如果您在一次调用中同时使用 "Properties File Path""Properties Content" 字段,它们不会按顺序处理,而是并行处理。因此,当您设置$LinkPL 时,$Link 的值仍然是旧的。解决方案是进行两个 env-inject 步骤,一个是注入 props 文件,另一个是利用结果。

例子:

输出:

此外,您不能以您尝试的方式在 shell 步骤中取消设置变量的值。取消设置只会影响那个 shell 步骤。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多