This is starting to drive me crazy .. but it seems like I am out of luck to figure it out by myself :/
I need to set up a mechanism to share string value between two slaves, for example, named slave A and slave B.
Currently most closest one I have found is this SO Question: Jenkins Slave Environment Variable Refresh
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?)
Currently I have this setup:
1) on A the job A is triggered.
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) 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
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?
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...
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?
Another SO Question and answer that needs user interaction, therefore not acceptable in my case: Jenkins - passing variables between jobs?
This also do not work in my case: http://comments.gmane.org/gmane.comp.java.hudson.user/37897
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 | a prodreleases
NODE_NAME | a
... this is for slave B , but it should be different values as this is originally for slave A ... What a hell??????????????????!!!! :/
I am starting to have feeling that root problem is that Jenkins has bug when resolving multiple slave NODE information.
Decided to create a Issue @ Jenkins jira: https://issues.jenkins-ci.org/browse/JENKINS-15397