It's all about the answers!

Ask a question

local variables in build forge steps


Steffen Kriese (381921) | asked Jan 29 '14, 10:45 a.m.
Hello,

I want to use a local variable in a step.  My test case on linux looks like this:

x=123
echo $x

build forge transforms this to.
118	29.01.14 09:30		SCRIPT	x=123
119	29.01.14 09:30		SCRIPT	echo x
and the output is
121	29.01.14 09:30		EXEC	x

looks like the pre parsing needs to be turned off for variable x.
Any idea hoe to do this?

Thanx, Steffen

 

2 answers



permanent link
Spencer Murata (2.3k115971) | answered Jan 29 '14, 10:54 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
If you want to turn off the BuildForge preparsing, _NO_PREPARSE_COMMAND can be set on the environment (set to anything) and that will bypass the Build Forge parsing.  Alternatively you can double up the $, like $$x, then Build Forge will interpret it down to $x, leaving the rest to the shell.

~Spencer

permanent link
Steffen Kriese (381921) | answered Jan 30 '14, 2:53 a.m.
Hello,

I changed my code as follows:

x=123
echo $$x
echo $x

but I don't get the 123 echoed.

here is the log:

115 30.01.14 01:49 EXEC Variablenerweiterung für Befehlszeile ausführen. 116 30.01.14 01:49 SET Verweis auf nicht definierte Variable: x. 117 30.01.14 01:49 SET Verweis auf nicht definierte Variable: x. 118 30.01.14 01:49 EXEC Shell [/bin/bash] wird gestartet. 119 30.01.14 01:49 SCRIPT #!/bin/bash 120 30.01.14 01:49 SCRIPT 121 30.01.14 01:49 SCRIPT x=123 122 30.01.14 01:49 SCRIPT echo $x 123 30.01.14 01:49 SCRIPT echo x 124 30.01.14 01:49 EXEC [/home/buildforge/Library_Build/BUILD_21@bflxx861.boeblingen.de.ibm.com] starten 125 30.01.14 01:49 EXEC x 126 30.01.14 01:49 EXEC x 127 30.01.14 01:49 EXEC [/home/buildforge/Library_Build/BUILD_21@bflxx861.boeblingen.de.ibm.com] beenden 128 30.01.14 01:49 RESULT 0

Kind Regards, Steffen

Comments
Spencer Murata commented Jan 30 '14, 8:24 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

You should declare the variable in the BF step using .tset or make the command runnable as one line like "x=123 && echo $$x".  Otherwise the change will be lost when BF generates the new shell for the next line.  The best practice here is to declare the variable in BF and not to rely on the shell variables themselves.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.