It's all about the answers!

Ask a question

How to set environment variables in Perl script to be available in BF?


Jirong Hu (1.5k9290258) | asked Sep 21 '12, 5:03 p.m.
 Hi

I need a perl script to manipulate the variables before next step.

In Step 1 I call a Perl script to set some system environment variables such as this: $ENV{'DIR'} = $DIR;
but in the next step $DIR is empty. 

Thanks
Jirong




3 answers



permanent link
Max Börebäck (16122) | answered Aug 12 '13, 2:44 p.m.
 If you have to set a large amount of environment varuables
Create a xml project file and load it
And in the step, make all the .bset commnds needed to set everything

I am using this method to load all the CELL variables via a perl api so I can extend the project dynamicaly with a perticular cell.

permanent link
David Parrott (2123) | answered Dec 12 '12, 7:06 a.m.
 See also my suggestions in https://jazz.net/forum/questions/95865/import-a-variable-from-a-ksh-script, which elaborate on David's and Spencer's replies.

Comments
Jojie Valiente commented Jul 23 '13, 11:58 p.m.

Hi David,

I'm running in Windows environment. Is there another solution?

Jojie


permanent link
David Brauneis (50611) | answered Sep 25 '12, 4:06 p.m.
JAZZ DEVELOPER
 I think that setting environment variables in the context of the shell (which is what you are doing) will not be available to the next step, because it runs in a new shell instance.

I think that you could make it a BF_Environment Variable if you wanted to do that and use the BF Services Perl Client to set (or update the value) of it in your Perl script.

Comments
Spencer Murata commented Oct 01 '12, 4:05 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Check out .tset and .bset in the help to persist variables in Build Forge builds. 


Jirong Hu commented Jun 26 '15, 10:03 a.m.

I wasn't made myself clear in the original post. This is what I did:


Step1 command: perl z:\Unix.pl SetEnvVar
The SetEnvVar() in Unix.pl will parse a long string and set each BF variable (I defined them in a BF environment attached to the BF project. This is the code:  $ENV{"BANNER_H"} = $g_BANNER_H; I thought this will set system environment variable then available in BF too.
Step2, echo ${BANNER_H} is empty.

There are lots of variables, so don't want to use API to set one by one. What's wrong here?





Jirong Hu commented Jun 26 '15, 10:09 a.m.

With less variables, I can use the API to set each of them from perl code like this: $build->updateBuildEnvEntryValue($buildEnvEntryToUpdate->getUuid(), $app_path);


Then with more than 20 variables, it's a bit messy so want to use API to set only one long  and well formatted string to BF, then try to parse there and again set individual variables to BF. 

I am on Windows too.

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.