locked
evaluation of task environment variables RRS feed

  • Question

  • How do I get environment variables evaluated before task execution.

    I would like to set an environment variable

    MCR_CACHE_ROOT to %TMP%\%CCP_JOBID%.%CCP_TASKID%

    but instead of getting an evaluated value like

    C:\user\username\appdata\local\1234.3

    (as I would if I used "set" in a cmd.exe) then I just get the variable names without any evaluation

    %TMP%\%CCP_JOBID%.%CCP_TASKID%

    I presume this is very simple and that I am missing the obvious part...

    Monday, May 14, 2018 2:43 PM

Answers

  • Hi Thomas,

      I think you could combine the two command together (first set env, then run your real command). Here is an example of the commandline:

           set mydir= && set mydir=%CCP_JOBID% && call echo %mydir%

    The output will be the job Id. You can replace "echo %mydir%" with your real task command, and mydir with your env variable you want to set (that is: set MCR_CACHE_ROOT=%TMP%\%CCP_JOBID%.%CCP_TASKID%)


    Qiufang Shi


    Tuesday, May 15, 2018 8:45 AM

All replies

  • Hi Thomas,

      I didn't understand your scenario. Do you want to know the variable setting before evaluation? If yes, you just need to get the task detail from the scheduler, for example, task view <jobid>.<taskId>

      The CCP_* environment variable will only be expanded when the task is about to dispatch to the compute node for execution; the values are being set by the scheduler for example, the name of the compute node "CCP_NODES".

      


    Qiufang Shi

    Tuesday, May 15, 2018 2:35 AM
  • Dear Quifang,

    Thanks for the swift reply. My use case is that I have a number of tasks that needs a unique temporary directory, specified by the environment variable MCR_CACHE_ROOT. For e.g. debugging it would be easy if the name of the temporary directory contained the job id and task id. Thus I would like to obtain the same functionallity as executing:

    set MCR_CACHE_ROOT=%TMP%\%CCP_JOBID%.%CCP_TASKID%

    in a task. Using "set" will expand / evaluate the environment variables.

    However, if I specify the environment variables in either a job or a task in a job then the environment variable MCR_CACHE_ROOT just contains MCR_CACHE_ROOT=%TMP%\%CCP_JOBID%.%CCP_TASKID% and not the expanded values which could look like C:\user\abcd\AppData\Local\34567.12

    Best regards,
    Thomas

    Tuesday, May 15, 2018 7:28 AM
  • Hi Thomas,

      I think you could combine the two command together (first set env, then run your real command). Here is an example of the commandline:

           set mydir= && set mydir=%CCP_JOBID% && call echo %mydir%

    The output will be the job Id. You can replace "echo %mydir%" with your real task command, and mydir with your env variable you want to set (that is: set MCR_CACHE_ROOT=%TMP%\%CCP_JOBID%.%CCP_TASKID%)


    Qiufang Shi


    Tuesday, May 15, 2018 8:45 AM
  • Thanks. Yes, that would work. I was just trying to avoid just that but I reckon that is the way to proceed.

    Thanks again for taking your time to provide the answer.

    Best regards,
    Thomas

    Tuesday, May 15, 2018 8:52 AM