Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
6 replies Latest Post - ‏2010-08-03T05:28:27Z by SystemAdmin
ScottDev
ScottDev
4 Posts
ACCEPTED ANSWER

Pinned topic Calling .bset from within conditional

‏2010-07-29T18:40:44Z |
Hi, I am trying to set a variable based on another variable. I have a series of conditional statements that decide what the variable gets initialized to, however, I've noticed that the variable does not exist outside the conditional block.

Here is pseudo code for what I want to accomplish from the step:

if( ${variable1} == "one" } then
.bset env "variable2=env1";
else if( ${variable1} == "two" } then
.bset env "variable2=env2";
else{
.bset env "variable2=default";
endif
.bset env "finalVar=${variable1}${variable2};

When I use this code, however, variable2 does not have a value in the final line of code, so it appears as "variable2". I am guessing this is just a weird syntax issue, but I cannot figure it out. Thanks for your help!
Updated on 2010-08-03T05:28:27Z at 2010-08-03T05:28:27Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    805 Posts
    ACCEPTED ANSWER

    Re: Calling .bset from within conditional

    ‏2010-07-29T18:57:06Z  in response to ScottDev
    The .bset changes do not take effect until the current step completes. So you can .bset var2 in 1 step, and then in the next step construct the final value.

    I think you want to use the .tset command for the var2, if available in your version of buildforge.
    • ScottDev
      ScottDev
      4 Posts
      ACCEPTED ANSWER

      Re: Calling .bset from within conditional

      ‏2010-07-29T20:03:36Z  in response to SystemAdmin
      Hi Leo,

      Thanks for your reply. I tried making the bset commands in one step, then the final .bset in another step, but still have the issue.

      I also tried the .tset command, and have the same issue. What does the .tset command do and how does it differ from .set and .bset? I couldnt find anything in the BuildForge documentation.

      Thanks again!
      • ScottDev
        ScottDev
        4 Posts
        ACCEPTED ANSWER

        Re: Calling .bset from within conditional

        ‏2010-07-29T22:06:57Z  in response to ScottDev
        I continued my testing and created two test scripts:

        STEP 1:
        if( "true" == "true" ) then
        .bset env "status=passed"
        echo "1. Status:${status}" > test.log
        endif
        .bset env "status=passed"
        echo "2. Status:${status}" > test.log
        STEP 2:
        echo "2. Status:${status}" > test.log
        When I run step 1 then Step two, the test.log reads as follows:
        1. Status:status
        2. Status:passed
        3. Status:passed

        It appears that for some reason the .bset is not working inside my if statement. Has anyone else seen this?

        Thanks
        • SystemAdmin
          SystemAdmin
          805 Posts
          ACCEPTED ANSWER

          Re: Calling .bset from within conditional

          ‏2010-07-29T22:29:03Z  in response to ScottDev
          My BuildForge env is not available right now to test with but at a guess (and I'm not saying this is a good thing if it works!)...
          Try declaring the variable before the if statement. Like this:

          STEP 1:
          .bset env "status=notset"
          if( "true" == "true" ) then
          .bset env "status=passed"
          echo "1. Status:${status}" > test.log
          endif
          .bset env "status=passed"
          echo "2. Status:${status}" > test.log

          STEP 2:
          echo "2. Status:${status}" > test.log
          • ScottDev
            ScottDev
            4 Posts
            ACCEPTED ANSWER

            Re: Calling .bset from within conditional

            ‏2010-07-30T13:43:30Z  in response to SystemAdmin
            Hi Mark, thanks for your reply. I tried your suggestion of defining the variable first, and that doesnt work either. When I run your code I get:

            1. Status:not set
            2. Status:passed
            3. Status:passed

            It seems that build forge just cant handle .bset from within conditionals. Does anyone know any way around this?
            • SystemAdmin
              SystemAdmin
              805 Posts
              ACCEPTED ANSWER

              Re: Calling .bset from within conditional

              ‏2010-08-03T05:28:27Z  in response to ScottDev
              Guys, you're mixing BF dot commands with script code. You can't do that, it never works(with it did).All Batch commands in a step are converted into .cmd file (or files if separated by BF commands) and ran by the shell on the build machine. Dot commands are executed by BF agent.
              At least that the way I understand it. The only "workaround" I found to it is to do shell logic that echoes what you want into a file and then load it with
              
              .bset env 
              "YOURVAR=`type myselection.txt`"