0

I am using a self-hosted deploy agent on a windows VM. The service is running under a "normal" windows administrative user in order to be able to access some system-specific installations and batch files. Whenever I try to run one of those batch files, some environment variables are not taken over from the windows-user the agent is running on.

For instance the variable %HOMEPATH%. I was able to proof this behavior by running this simple step:

          - task: CmdLine@2
            displayName: 'test set'
            inputs:
              script: | 
                echo HOMEPATH
                echo %HOMEPATH%

Resulting in

Starting: test set
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:\azagent\A1\_work\_temp\3a5484d6-470e-45df-a3b8-0631f3fa373f.cmd""
HOMEPATH
ECHO is off.
Finishing: test set

The variable %HOMEPATH% is crucial for some git commands since it defines the file path for .gitconfig which contains the git user / email. I tried to re-install the agent which was a success (variable was set properly). But it lasted only until the next reboot.

Is there any parameter/option I can set to forward these environment variables to the run of the pipeline?

I would expect the pipeline agent to "forward" all windows user-specific environment variables to the pipeline steps.

Edit: Added info about administrative rights of windows user.

  • Hi Silvio, AFAIK System variables should be pushed as Variables into the Job Session. As this is Bash (CmdLine@2) i would try to access the HOMEPATH as $HOMEPATH. Does it work? In case it doesn't work try to run the Agent under Service or Admin Account. (ref: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#access-variables-through-the-environment) – Mario Dietner May 01 '23 at 17:52
  • Hi Mario, thank you for your input. I forget to mention that the windows user is an administrator. The description of CmdLine@2 describes that on a windows the task is corresponding to cmd.exe, see [here](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/cmd-line-v2?view=azure-pipelines). Means accessing vars by using `%myvar%` should work fine. At least it works for other variables. – silvio.ledergerber May 02 '23 at 05:39
  • Hi Silvio, i noticed the echo command for the variable states "ECHO is off." - if the variable would be empty it should actually print an empty line in your case. Maybe its worth trying turning "echo on" in a previous step? – Mario Dietner May 02 '23 at 08:09
  • Hi Mario - This happens if the variable is empty. Can be reproduced on any windows system when trying to echo an empty variable. – silvio.ledergerber May 02 '23 at 13:32

0 Answers0