locked
Setting an environment variable RRS feed

  • Question

  • Is there any way to set an environment variable in the build workflow that can then be used throughout the process. I have a few variables that need to be set for running generic automated tests as well as to other tools.

    I have tried using the InvokeProcess activity, but the variable does not get set. Below is the values for the activity.

    Filename = CMD.EXE

    Arguments = String.Format("/c SET MyVar={0}", BinariesDirectory)

     

    Is there another way to do this?

     

     

    Thanks,

    Anthony

    Tuesday, September 7, 2010 2:21 PM

Answers

  • I have been able to resolve this problem. The correct activity to use is InvokeMethod.

     

    Give it the following values:

    MethodName = SetEnvironmentVariable

    Parameters = 

    Direction = In;Type = String; Value=String.Format("MyVar")

    Direction = In;Type = String; Value=BinariesDirectory

    TargetType = System.Environment

     

     

    Anthony

    • Marked as answer by Anthony Hunter Tuesday, October 19, 2010 3:14 PM
    Tuesday, October 19, 2010 3:14 PM

All replies

  • Hi,

    I think this issue is related to Child Process Inheritance, this thread explain it in detail. http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/e18b3f0f-6da1-48cd-a525-f84c3a85a2b4 (WorkFlow is same as MSBuild, and InvokeProcess Activity is like EXEC task ).

    One workaround is to create  variables in the workflow and pass them as parameters.


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
    Wednesday, September 8, 2010 5:05 AM
    Moderator
  • The problem here is for my generic test to run, it requires a couple of environment variables to be set. How can I set these so that when the generic test gets executed, it will complete successfully during the build process?

    I can foresee this being a problem with other tools we may want to include in the build. If we can create environment variables, then how can they be executed?

    Monday, September 13, 2010 7:55 PM
  • Hi,

    When you the build workflow start, System will set the environment variables for it.

    If you invoke InvokeProcess to run Set command, the envirenment variable only take effect in the process. Even though you can use SetX command, the new envirenment variable does not affect the Build Workflow.

    When the build workflow start a test, the test will inherit the environment variables of the build workflow , which means that the new envirenment variable will not used by test.

    So my suggestion is use parameters instead of environment variables. and pass the parameters to test. or you can store the values somewhere(like a txt file) that test could access .


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
    Tuesday, September 14, 2010 5:58 AM
    Moderator
  • If I create new biuld variables with the values I want, how can I then pass those to my test? My tests are being executed using the MSTest activity. Sorry, I'm missing something here because this seems to be way more difficult than it should be.

    Here is what I have on my test case:

    Executable: %ComSpec%

    Run Settings (example): /c %MY_VAR%\test.exe %TEST_DIR%\test

    I see there is a spot to set environment variables, but I can't find any help on what can go into the value column. Will this accept a build property like $(BuildOutput)?

     

    Thanks,

    Anthony

    • Edited by Anthony Hunter Tuesday, September 14, 2010 12:53 PM Adding image
    Tuesday, September 14, 2010 12:51 PM
  • Hi Anthony,

    Sorry that I cannot see the pic, could you upload it to http://skydrive.live.com?


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com
    Wednesday, September 15, 2010 6:01 AM
    Moderator
  • Here is the image.

     

    http://cid-226b2b3b8811754b.photos.live.com/self.aspx/Public/GenericTestCaseExample.PNG

    (Sorry, can't figure out how to embed it in the message.)

    Wednesday, September 15, 2010 12:58 PM
  • Just wondering if you have any ideas on how I can get my generic tests to work?

     

    Thanks,

    Anthony

    Wednesday, September 22, 2010 12:40 AM
  • I have been able to resolve this problem. The correct activity to use is InvokeMethod.

     

    Give it the following values:

    MethodName = SetEnvironmentVariable

    Parameters = 

    Direction = In;Type = String; Value=String.Format("MyVar")

    Direction = In;Type = String; Value=BinariesDirectory

    TargetType = System.Environment

     

     

    Anthony

    • Marked as answer by Anthony Hunter Tuesday, October 19, 2010 3:14 PM
    Tuesday, October 19, 2010 3:14 PM