PATH messes up BF?
I'm not sure where to go with this one, but if anyone has an opinion, I'll consider it.
What I'm trying to do is call a cqperl program twice on a Windows agent inside a library (BF 7.1.1.4). The first time it spits out a message a human can read (line 422) and the second time (line 428) I want it to return a value in a variable so BuildForge can take other actions later. This all works just fine except under one condition: if the callers BF-supplied Environment has an environment variable named "PATH" in it, I get the output below. Ugly. It looks like having the keyword PATH in the environment messes *something* up beyond repair.
OK fine, so I tried to code around it - I'll just put the path I need in front of the existing path. But that doesn't work; it looks like the command processor restarts - see lines 426 and 427. And line 430 shows the path is fouled up again in time for the second run of the CQperl program, causing it to fail.
It's tempting just to tell users to not use the word PATH in their environment strings, but I can't control that and my library ought to be robust enough to circumvent this kind of problem.
Any other ideas?
Jonathan Allan
Step as scripted:
REM Set path up even if caller has own path defined
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
REM Print the ticket number and state to the job log for future auditor perusal as a console message
cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
REM
REM Return the ticket state as a string for the calling project to use
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
.bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
REM
And the output:
406 06/24/11 11:33AM SCRIPT REM Set path up even if caller has own path defined
407 06/24/11 11:33AM SCRIPT echo %path%
408 06/24/11 11:33AM SCRIPT set PATH=D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;%PATH%
409 06/24/11 11:33AM SCRIPT echo %path%
410 06/24/11 11:33AM SCRIPT REM
411 06/24/11 11:33AM SCRIPT REM Print the ticket number and state to the job log for future auditor perusal as a console message
412 06/24/11 11:33AM SCRIPT cqperl d:\builds\BuildTools\getcmsinfotext.pl 111111 Message
413 06/24/11 11:33AM SCRIPT REM
414 06/24/11 11:33AM SCRIPT REM Return the ticket state as a string for the calling project to use
415 06/24/11 11:33AM SCRIPT echo %path%
416 06/24/11 11:33AM SCRIPT set PATH=D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;%PATH%
417 06/24/11 11:33AM SCRIPT echo %path%
418 06/24/11 11:33AM SCRIPT REM
419 06/24/11 11:33AM EXEC start
420 06/24/11 11:33AM EXEC C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
421 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
422 06/24/11 11:33AM EXEC CMS Ticket: "111111" is validated in CMS Database with System ID: "22797", State: "Implemented" and allowable Flag: "W"
423 06/24/11 11:33AM EXEC Message: "The CMS record Status is Implemented, which is not a valid status for deploying changes to production."
424 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
425 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
426 06/24/11 11:33AM EXEC end
427 06/24/11 11:33AM RESULT 0 (0)
428 06/24/11 11:33AM STEP .bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
429 06/24/11 11:33AM EXEC end
430 06/24/11 11:33AM EXEC .bset env 'CMS_TICKET_STATUS' = ''cqperl' is not recognized as an internal or external command,operable program or batch file.' (New Variable)
524 06/24/11 11:33AM EXEC Locale set to 'English_United States.1252'
627 06/24/11 11:33AM EXEC Performing variable expansion on command line
629 06/24/11 11:33AM SCRIPT REM
630 06/24/11 11:33AM SCRIPT echo %path%
631 06/24/11 11:33AM SCRIPT REM
632 06/24/11 11:33AM EXEC start
633 06/24/11 11:33AM EXEC C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
634 06/24/11 11:33AM EXEC end
635 06/24/11 11:33AM RESULT 0 (0)
What I'm trying to do is call a cqperl program twice on a Windows agent inside a library (BF 7.1.1.4). The first time it spits out a message a human can read (line 422) and the second time (line 428) I want it to return a value in a variable so BuildForge can take other actions later. This all works just fine except under one condition: if the callers BF-supplied Environment has an environment variable named "PATH" in it, I get the output below. Ugly. It looks like having the keyword PATH in the environment messes *something* up beyond repair.
OK fine, so I tried to code around it - I'll just put the path I need in front of the existing path. But that doesn't work; it looks like the command processor restarts - see lines 426 and 427. And line 430 shows the path is fouled up again in time for the second run of the CQperl program, causing it to fail.
It's tempting just to tell users to not use the word PATH in their environment strings, but I can't control that and my library ought to be robust enough to circumvent this kind of problem.
Any other ideas?
Jonathan Allan
Step as scripted:
REM Set path up even if caller has own path defined
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
REM Print the ticket number and state to the job log for future auditor perusal as a console message
cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
REM
REM Return the ticket state as a string for the calling project to use
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
.bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
REM
And the output:
406 06/24/11 11:33AM SCRIPT REM Set path up even if caller has own path defined
407 06/24/11 11:33AM SCRIPT echo %path%
408 06/24/11 11:33AM SCRIPT set PATH=D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;%PATH%
409 06/24/11 11:33AM SCRIPT echo %path%
410 06/24/11 11:33AM SCRIPT REM
411 06/24/11 11:33AM SCRIPT REM Print the ticket number and state to the job log for future auditor perusal as a console message
412 06/24/11 11:33AM SCRIPT cqperl d:\builds\BuildTools\getcmsinfotext.pl 111111 Message
413 06/24/11 11:33AM SCRIPT REM
414 06/24/11 11:33AM SCRIPT REM Return the ticket state as a string for the calling project to use
415 06/24/11 11:33AM SCRIPT echo %path%
416 06/24/11 11:33AM SCRIPT set PATH=D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;%PATH%
417 06/24/11 11:33AM SCRIPT echo %path%
418 06/24/11 11:33AM SCRIPT REM
419 06/24/11 11:33AM EXEC start
420 06/24/11 11:33AM EXEC C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
421 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
422 06/24/11 11:33AM EXEC CMS Ticket: "111111" is validated in CMS Database with System ID: "22797", State: "Implemented" and allowable Flag: "W"
423 06/24/11 11:33AM EXEC Message: "The CMS record Status is Implemented, which is not a valid status for deploying changes to production."
424 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
425 06/24/11 11:33AM EXEC D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
426 06/24/11 11:33AM EXEC end
427 06/24/11 11:33AM RESULT 0 (0)
428 06/24/11 11:33AM STEP .bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
429 06/24/11 11:33AM EXEC end
430 06/24/11 11:33AM EXEC .bset env 'CMS_TICKET_STATUS' = ''cqperl' is not recognized as an internal or external command,operable program or batch file.' (New Variable)
524 06/24/11 11:33AM EXEC Locale set to 'English_United States.1252'
627 06/24/11 11:33AM EXEC Performing variable expansion on command line
629 06/24/11 11:33AM SCRIPT REM
630 06/24/11 11:33AM SCRIPT echo %path%
631 06/24/11 11:33AM SCRIPT REM
632 06/24/11 11:33AM EXEC start
633 06/24/11 11:33AM EXEC C:\Program Files\IBM\SDP\jdk\bin;C:\Program Files\IBM\SDPShared\plugins\org.apache.ant_1.7.0.v200803061910\bin;PATH;.
634 06/24/11 11:33AM EXEC end
635 06/24/11 11:33AM RESULT 0 (0)
4 answers
{snipped}
Step as scripted:
REM Set path up even if caller has own path defined
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
REM Print the ticket number and state to the job log for future auditor perusal as a console message
cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
REM
REM Return the ticket state as a string for the calling project to use
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
.bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
REM
{snipped}
Ok, there are at least two concepts afoot that make your approach impossible.
First, there is the concept of 'step parts'. This encompasses both the way commands are transferred to the agent and the way the agent executes them. Dot commands delimit these pieces of a step. Shell commands between the dot commands are sent en masse to the agent for execution as a script. Tinkering about with the environment inside that script is fair game, but it won't be preserved between step parts (as that is a new block of commands executing in a new script in a new process). Therefore, the environment you set up before your ".bset" command is totally unavailable to that dot command's execution.
Second, consider where dot commands execute. The .bset dot command, particularly, executes on the engine. Build Forge does not replicate ad hoc endpoint agent environment changes (like what you are doing in your script) back to the engine's build environment (consider the chaos that would cause, in addition to the parsing complexity or impossibility if the environment were altered via compiled executable).
My suggestion for success is this - quit tinkering with the PATH environment variable. You already have the path to the executable in your $CQPERL_PATH var, just prepend your command with that, i.e. :
${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
and
.bset env "CMS_TICKET_STATUS = `${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
-steve
{snipped}
Step as scripted:
REM Set path up even if caller has own path defined
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
REM Print the ticket number and state to the job log for future auditor perusal as a console message
cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
REM
REM Return the ticket state as a string for the calling project to use
echo %%path%%
set PATH=${CQPERL_PATH}%%PATH%%
echo %%path%%
REM
.bset env "CMS_TICKET_STATUS = `cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
REM
{snipped}
Ok, there are at least two concepts afoot that make your approach impossible.
First, there is the concept of 'step parts'. This encompasses both the way commands are transferred to the agent and the way the agent executes them. Dot commands delimit these pieces of a step. Shell commands between the dot commands are sent en masse to the agent for execution as a script. Tinkering about with the environment inside that script is fair game, but it won't be preserved between step parts (as that is a new block of commands executing in a new script in a new process). Therefore, the environment you set up before your ".bset" command is totally unavailable to that dot command's execution.
For an example, consider this contrived step command block :
these commands run
together in one script
I can do set FOO=BAR and
echo $FOO and get BAR
.dotcommand1
these commands run
together in another script
because of .dotcommand1,
echo $FOO will print nothing
now because $FOO is no longer
defined
.dotcommand2
the commands run together
in the last script, delimited
by .dotcommand2
Second, consider where dot commands execute. The .bset dot command, particularly, executes on the engine. Build Forge does not replicate ad hoc endpoint agent environment changes (like what you are doing in your script) back to the engine's build environment (consider the chaos that would cause, in addition to the parsing complexity or impossibility if the environment were altered via compiled executable).
My suggestion for success is this - quit tinkering with the PATH environment variable. You already have the path to the executable in your $CQPERL_PATH var, just prepend your command with that, i.e. :
${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
and
.bset env "CMS_TICKET_STATUS = `${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
-steve
My suggestion for success is this - quit tinkering with the PATH environment variable. You already have the path to the executable in your $CQPERL_PATH var, just prepend your command with that, i.e. :
${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER Message
and
.bset env "CMS_TICKET_STATUS = `${CQPERL_PATH}\cqperl $BUILD_TOOLS_DIR\$RETURN_CMS_TICKET_STATUS $CMS_TICKET_NUMBER ReturnState`"
-steve
Except that $CQPERL_PATH contains:
D:\IBM\RationalSDLC\common\CM\bin;D:\IBM\RationalSDLC\ClearQuest;D:\IBM\RationalSDLC\ClearQuest\cqcli\bin;D:\IBM\Build Forge;D:\Program Files\IBM\RationalSDLC\common;
Suggestions as to which piece to prefix the cqperl calls with so it doesn't flake out like cleartool was?