It's all about the answers!

Ask a question

Referring to Windows variables


Tim McDaniel (401146) | asked Jun 08 '10, 8:31 a.m.
We run builds on a Windows machine. There's a similar problem for
UNIX-like systems, I presume.

I want to refer to a Windows variable in a step's statement.
I currently have

if %%errorlevel%% neq 0 (echo error in checkstyle run for app& exit /b 1)

This works only by coincidence, so to speak. BuildForge sees
%errorlevel%, and because it happens not to be a BuildForge property,
it emits

SET Reference to undefined variable: errorlevel

but substitutes "errorlevel" for it. The statement is then presented
to Windows as

if %errorlevel% neq 0 (echo error in checkstyle run for app& exit /b 1)

which does what I want.

I really dislike referring to undefined / undeclared variables:
ever since FORTRAN IV I've thought it sucked, and I wish it were a
fatal error. Is there some other way to escape the % characters so
that Windows sees it but that Build Forge does not?

It just occurred to me that I could define a Build Forge property
named errorlevel with the value errorlevel, and so on for every
Windows variable that I want to refer to, but that seems a little
kludgy if there's a Build Forge way.




--
Tim McDaniel, tmcd@panix.com

5 answers



permanent link
Tim McDaniel (401146) | answered Jun 08 '10, 1:35 p.m.
In article <humajb>,
bju <ulbricht> wrote:
Tim McDanielwrote:
We run builds on a Windows machine. There's a similar problem for
UNIX-like systems, I presume.
I want to refer to a Windows variable in a step's statement.

There is a Build Forge trigger environment variable named
_NO_PREPARSE_COMMAND . If you set that variable in your environment
for the step to any value, the system will not parse and resolve
variable values before sending commands to the agent.

Thank you.

Just to make sure: that works because Build Forge puts all its
properties into the Windows/UNIXy environment?

I suspect that, if there aren't any drawbacks, it would be the default
or just invarible. The only problem I could see is if the Windows
environment can't store a Build Forge environment variable -- like

- if a Build Forge environment variable name can have characters that
Windows doesn't allow

- if Build Forge environment variable names are case-sensitive but
Windows's are not

--
Tim McDaniel, tmcd@panix.com

permanent link
Brent Ulbricht (2.5k11) | answered Jun 08 '10, 4:40 p.m.
JAZZ DEVELOPER
We run builds on a Windows machine. There's a similar problem for
UNIX-like systems, I presume.

I want to refer to a Windows variable in a step's statement.
I currently have

if %%errorlevel%% neq 0 (echo error in checkstyle run for app& exit /b 1)

This works only by coincidence, so to speak. BuildForge sees
%errorlevel%, and because it happens not to be a BuildForge property,
it emits

SET Reference to undefined variable: errorlevel

but substitutes "errorlevel" for it. The statement is then presented
to Windows as

if %errorlevel% neq 0 (echo error in checkstyle run for app& exit /b 1)

which does what I want.

I really dislike referring to undefined / undeclared variables:
ever since FORTRAN IV I've thought it sucked, and I wish it were a
fatal error. Is there some other way to escape the % characters so
that Windows sees it but that Build Forge does not?

It just occurred to me that I could define a Build Forge property
named errorlevel with the value errorlevel, and so on for every
Windows variable that I want to refer to, but that seems a little
kludgy if there's a Build Forge way.




--
Tim McDaniel, tmcd@panix.com


Hi Tim,

There is a Build Forge trigger environment variable named _NO_PREPARSE_COMMAND . If you set that variable in your environment for the step to any value, the system will not parse and resolve variable values before sending commands to the agent.

bju

permanent link
Brent Ulbricht (2.5k11) | answered Jun 09 '10, 8:46 a.m.
JAZZ DEVELOPER
In article <humajb>,
bju <ulbricht> wrote:
Tim McDanielwrote:
We run builds on a Windows machine. There's a similar problem for
UNIX-like systems, I presume.
I want to refer to a Windows variable in a step's statement.

There is a Build Forge trigger environment variable named
_NO_PREPARSE_COMMAND . If you set that variable in your environment
for the step to any value, the system will not parse and resolve
variable values before sending commands to the agent.

Thank you.

Just to make sure: that works because Build Forge puts all its
properties into the Windows/UNIXy environment?

I suspect that, if there aren't any drawbacks, it would be the default
or just invarible. The only problem I could see is if the Windows
environment can't store a Build Forge environment variable -- like

- if a Build Forge environment variable name can have characters that
Windows doesn't allow

- if Build Forge environment variable names are case-sensitive but
Windows's are not

--
Tim McDaniel, tmcd@panix.com

Hi Tim,

The documentation lists this information about variable names, which hopefully prevents naming problems.


Variable names can use only alphanumeric characters (a-z, A-Z, 0-9) and the underscore character ( _ ) in a name. The maximum length is 255 bytes:

* Single-byte character sets: 255 characters
* Double-byte character sets: 127 characters



One of the other things to watch out for is that your steps are less cross platform now because of the use of %VAR_NAME% or $VAR_NAME to expand variables.

bju

permanent link
Tim McDaniel (401146) | answered Jun 22 '10, 8:41 a.m.
In article <hulr88>,
Tim McDaniel <tmcd> wrote:
We run builds on a Windows machine. There's a similar problem for
UNIX-like systems, I presume.

I want to refer to a Windows variable in a step's statement.
I currently have

if %%errorlevel%% neq 0 (echo error in checkstyle run for app& exit /b 1)

This works only by coincidence, so to speak. BuildForge sees
%errorlevel%, and because it happens not to be a BuildForge property,
it emits

SET Reference to undefined variable: errorlevel

but substitutes "errorlevel" for it. The statement is then presented
to Windows as

if %errorlevel% neq 0 (echo error in checkstyle run for app& exit /b 1)

which does what I want.

I really dislike referring to undefined / undeclared variables:
ever since FORTRAN IV I've thought it sucked, and I wish it were a
fatal error. Is there some other way to escape the % characters so
that Windows sees it but that Build Forge does not?

It just occurred to me that I could define a Build Forge property
named ERRORLEVEL with the value ERRORLEVEL

I tried that. What I forgot is that Build Forge puts all its
variables into the environment. That means that it created a CMD
environment variable named ERRORLEVEL with value ERRORLEVEL.

Which (I believe) turned off the special meaning of ERRORLEVEL: that
is, CMD no longer set it to be an integer representing the exit code
of the last command.

Which screwed up BAT files in so many weird ways it wasn't funny.
And ant on Windows is actually ant.bat, so it started to report BUILD
SUCCESSFUL but an ant run calling it saw it as failed. Really
freakin' mysterious.

So: SEVERE TIRE DAMAGE MAY RESULT if you change builtin Windows or
Unix variables in a Build Forge environment.

I think you could, for example, define a Build Forge variable
JOE_BLOGGS to be ERRORLEVEL, and then use %%JOE_BLOGGS%% to get
%ERRORLEVEL%.

But I'd still like a way that's less kludgy than defining a trampoline
variable like that or turning off all Build Forge variable expansion
in the step.

--
Tim McDaniel, tmcd@panix.com

permanent link
Tim McDaniel (401146) | answered Jul 29 '10, 2:50 p.m.
Just an FYI.

For this particular application, checking for ERRORLEVEL NEQ 0 in
Windows but not causing a Build Forge "undefined variable" warning,
I now realize I can do
if errorlevel 1 (some actions)
if not errorlevel 0 (the same actions)
But I plan to avoid the entire problem of variable reference by
calling a CMD file.

--
Tim McDaniel, tmcd@panix.com

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.