将系统Env变量传递给Jenkins从站 [英] Passing System Env variable into Jenkins Slave

查看:116
本文介绍了将系统Env变量传递给Jenkins从站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这开始让我发疯..但是我似乎不走运自己独自解决它:/

This is starting to drive me crazy .. but it seems like I am out of luck to figure it out by myself :/

我需要建立一种在两个从站之间共享字符串值的机制,例如,名为从站 A 和从站 B .

I need to set up a mechanism to share string value between two slaves, for example, named slave A and slave B.

我最近找到的最接近的是这个问题: Jenkins从属环境变量刷新

Currently most closest one I have found is this SO Question: Jenkins Slave Environment Variable Refresh

但是它仍然旨在使能在构建脚本中进行访问,而不是在Slaves环境变量本身中进行访问. (相关的SO问题:如何使用环境变量Windows批处理命令在Jenkins中运行?)

But it still aims to enable access in buildscripts, not in the Slaves environment variable itself. (related SO Question: How are environment variables used in Jenkins with Windows Batch Command?)

当前,我有以下设置:

1)在 A 上触发了作业 A .

1) on A the job A is triggered.

它执行以下Windows批处理代码(显然,实际路径已替换为<>"):

It performs this windows batch code (actual paths, obviously, are replaced with '<>'):

cmd /c start java -jar <path_of_slave>\slave.jar -jnlpUrl  <url_of_slave>/slave-agent.jnlp

setenv.exe /m HOR_BUILD_ID -delete
setenv.exe /m HOR_BUILD_ID %BUILD_NUMBER%
setenv.exe /m HOR_UPSTREAM_ID -delete
setenv.exe /m HOR_UPSTREAM_ID %JOB_NAME%

不言而喻的直率的恕我直言.

Pretty self-explanatory and straight-forward imho.

2) A 上的作业具有上游作业 B ,该作业在成功构建后触发. 因此,在从属 B 中, B 构建执行此批处理代码(显然,实际路径已替换为'<>'):

2) The job on A have upstream job B, that is triggered on successful build. So, in the slave B the B build executes this batch code(actual paths, obviously, are replaced with '<>'):

SetLocal EnableDelayedExpansion

@echo off
@echo --- Refreshing Environemnt variables... 
@echo on
set prgfil=%ProgramFiles(x86)%
call "%WORKSPACE%\..\..\..\tools\misc\resetvars.bat"
@echo --- Reading environment variables... 
copy /y "<path_containing_%HOR_UPSTREAM_ID%_variable" "<path_containing_%HOR_BUILD_ID%_variable"
if !errorlevel!==0 goto ok1
goto error
:ok1

goto end

:error
EndLocal
exit /b 1

:end
EndLocal

注意:resetvars.bat和resetvars.vbs取自此SO问题:

NOTE: resetvars.bat and resetvars.vbs is taken from this SO Question: Is there a command to refresh environment variables from the command prompt in Windows?

输出(%HOR_BUILD_ID%和%HOR_UPSTREAM_ID%值)仍然过时了……刷新新变量的唯一方法是重新启动该织补詹金斯(主)服务,但这绝对是不可行的. CI环境...

The output (%HOR_BUILD_ID% and %HOR_UPSTREAM_ID% values), still, is outdated ... only way to get new variables refreshed is to restart that darn jenkins (master) service, but this is definetly no-go in the CI environment...

现在的问题浮出水面-触发 B 上的构建作业 B 时,如何使这些变量刷新/重新读取,以便我可以访问系统变量从奴隶不使用,例如,EnvInject插件?

The question now surfaces - how to make those variables to be refreshed / re-read when the build job B on B is triggered, so I could access system variables from slave w/o using, for example, EnvInject plugin?

需要用户交互的另一个SO问答,因此在我的情况下是不可接受的: Jenkins-在作业之间传递变量?

Another SO Question and answer that needs user interaction, therefore not acceptable in my case: Jenkins - passing variables between jobs?

在我的情况下,这也不起作用: http://comments.gmane.org/gmane.comp.java.hudson.user/37897

This also do not work in my case: http://comments.gmane.org/gmane.comp.java.hudson.user/37897

也许从站及其核心响应节点无法正确接收变量/无法正确解析其环境,从而导致无法从全局环境变量中检索信息?抓住它,突然间一些有趣的 Environment变量配置数据引起了我的注意:

Maybe the Slave and its coresponding node do not recieve variable / resolve its environment coreectly, causing to be unable to retrieve information form Global envirtonemtn variables? Cechked it out and suddenly some interesting Environment variable config data cought my eye:

NODE_LABELS |产品发布

NODE_LABELS | a prodreleases

NODE_NAME |一个

NODE_NAME | a

...这是用于从属 B 的,但是应该使用不同的值,因为它最初是用于从属 A 的. ????????????? !!!! :/

... this is for slave B , but it should be different values as this is originally for slave A ... What a hell??????????????????!!!! :/

我开始感觉到根本问题是詹金斯在解决多个从节点的NODE信息时出现了错误.

I am starting to have feeling that root problem is that Jenkins has bug when resolving multiple slave NODE information.

决定创建一个问题@ Jenkins jira: https://issues.jenkins- ci.org/browse/JENKINS-15397

Decided to create a Issue @ Jenkins jira: https://issues.jenkins-ci.org/browse/JENKINS-15397

推荐答案

您是否看过添加参数化触发器插件?

Have you looked at adding parameterized trigger plugin?

https://wiki.jenkins-ci.org/display/JENKINS/参数化+ Trigger +插件

这应该允许您将参数从第一个作业传递到第二个作业(例如要删除的作业名称).

This should allow you to pass parameters from the first job to the second (like the job name to delete).

这篇关于将系统Env变量传递给Jenkins从站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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