Jenkins Git Publisher标签未检测到环境变量 [英] Jenkins Git Publisher tag not detecting environment variables

查看:497
本文介绍了Jenkins Git Publisher标签未检测到环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Jenkins bash脚本中,我导出以下环境变量:

In my Jenkins bash script, I export the following environment variable:

export TAG_NAME=v$LIVE_VERSION.$LIVE_BUILD

在Git发布者部分中,我试图创建一个标签名称字段,并在其中填充$TAG_NAME,但是它试图创建一个字面名称为$TAG_NAME的标签,而不是用环境变量.

In the Git publisher section, I am trying to create a tag with the tag name field filled with $TAG_NAME, but it is trying to create a tag literally with the name $TAG_NAME instead of substituting in the value for the environment variable.

注意:这不是

Note: this is not a duplicate of this SO question, as the answer works for the asker, but for some reason does not work for me.

推荐答案

我假设您通过Jenkins中的执行外壳"步骤开始bash吗?

I'm assuming you started bash via an "Execute shell" step in Jenkins?

这里的问题是shell环境变量与Jenkins使用的环境变量不同.虽然您可以在bash中使用某些Jenkins变量(转到<your_jenkins_server_address>/env-vars.html/以查看哪些变量),但是您不能反向执行.当bash完成时,您在bash中设置的所有变量都将消失.

The problem here is that shell environment variables are not the same as the environment variables used by Jenkins. While you can use certain Jenkins variables in bash (go to <your_jenkins_server_address>/env-vars.html/ to see which ones), you cannot do the reverse. Any variable you set in bash is gone when bash finishes.

一种解决方法是将标签写入文件并使用Jenkins读取它们 EnvInject插件.该插件可以读取属性文件,并将所有属性添加为Jenkins环境变量.

A workaround is to write your tags to file and read them in using the Jenkins EnvInject plugin. The plugin can read a properties file and add all properties as Jenkins environment variables.

例如,bash写入文件:

For example, bash writing to file:

echo TAG_NAME=v$LIVE_VERSION.$LIVE_BUILD > tags.txt

EnvInject插件读取文件并注入其属性,以便Jenkins可以使用它:

EnvInject plugin reading the file and injecting its properties so Jenkins can use it:

这篇关于Jenkins Git Publisher标签未检测到环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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