Hi, I am trying to pass environment variables to an exec job:
<stage name="defaultStage">
<jobs>
<job name="defaultJob">
<tasks>
<exec command="/bin/echo" args="REVISION: ${GO_REVISION}" />
</tasks>
</properties>
</job>
</jobs>
</stage>The output:
[cruise] setting environment variable 'GO_REVISION' to value '7116'
REVISION: ${GO_REVISION}
Should this variable not be made available to the job?
Comments
8 comments
Hi Brett
You specify variables on an job by adding an <environmentvariables> section to the job definition.
Hi Brett
I think it is a syntax issue - The variable should be specified as %GO_REVISION% when passed in an argument. I can certainly use the revision variables when I specify them in this form
Hi Ian,
Thanks for the comment. That would most likely be on a Windows platform. I forgot to mention that we are running a linux build environment.
Anju: testing now.
Anju: I already had that config. Here is the relevant code snippet and output:
Configuration:
<pipeline name="Test">
<materials>
<svn url="http://svn.mycompany.com/svn/PROJECT/trunk/component" username="username" password="password" autoUpdate="false" materialName="svn_material" />
</materials>
<stage name="Test">
<jobs>
<job name="test">
<environmentvariables>
<variable name="REVISION">${GO_REVISION_SVN_MATERIAL}</variable>
</environmentvariables>
<tasks>
<exec command="/bin/echo" args="REVISION: $REVISION" />
</tasks>
</job>
</jobs>
</stage>
</pipeline>
Output:
Hi Brett,
Since echo command does not understand environment variables, its the shell thats does the substitution, the exec task needs to have the command set as "bash" with echo and its arguments as argument. So your exec task now looks like
<exec command="/bin/bash" args="-c 'echo REVISION: $REVISION'"/> /* Notice the single quote around echo. That has stumped us (Go devs) a few times */
This would print - REVISION: ${GO_REVISION_SVN_MATERIAL}
But I guess you want REVISION: 7187 to be output, so you can change the exec task to
<exec command="/bin/bash" args="-c 'echo ${GO_REVISION_SVN_MATERIAL}'"/>
FWIW, for your scripts (shell, ANT, NANT), the environment variables that Go sets are available like any other system environment variables.
Hope this helps. Let me know if you need any further questions.
Regards,
Rajesh
Ok, great. Thanks Rajesh, that does work. I think it would probably be best to then write system scripts or project-specific scripts and execute them, rather that doing it all directly.
What am I doing wrong here (this is declared within a <job> tag:
<environmentvariables>
<variable name="REVISION">${GO_REVISION_SVN_MATERIAL}</variable>
</environmentvariables>
Output:
Hi Brett,
In this case, Go is just assigning the value ${GO_REVISION_SVN_MATERIAL} to the REVISION environment variable and not substituting it. Go currently does not support recursive environment variable substitution.
To solve your problem, you can use the env. variable GO_REVISION_SVN_MATERIAL in your scripts directly.
However, if your scripts need the REVISION env. variable to be set and its value to be same as GO_REVISION_SVN_MATERIAL you can use this exec task (or do it in separate script)
<exec command="/bin/bash" args="-c 'REVISION=${GO_REVISION_SVN_MATERIAL}'"/>
Hope this helps.
Rajesh
Ok great, thanks Rajesh.
Please sign in to leave a comment.