Search code examples
azureazure-devopsazure-devops-pipelines

Issue with release pipeline: Powershell script is not running in the working directory specified


In my release pipeline, I have specified the working directory for the powershell under the advanced options as $(System.DefaultWorkingDirectory)/_{project name}

working directory

However, when the powershell script ran, the working directory of the script is C:\Windows\System32\WindowsPowerShell\v1.0

Any attempt to change the working directory in the powershell script resulted in an error

"Cannot find path 'D:\a\r1\a_{project name}' because it does not exist".

Note: My artifact was downloaded from this path so it should exist.

Does anyone know what is wrong?


Solution

  • The path "C:\Windows\System32\WindowsPowerShell\v1.0" is the installation directory of 'powershell.exe' on the agent machine. It should not be the default working directory of the PowerShell task.

    On the Microsoft-hosted Windows agents, normally '$(System.DefaultWorkingDirectory)' should be "D:\a\r1\a", and "$(System.DefaultWorkingDirectory)/_{project name}" should be "D:\a\r1\a\_{project name}" not "D:\a\r1\a_{project name}".

    It seemed did not correctly combine the path string for the specified working directory. A slash (\) was missed that caused the system can't find the path.

    You can try to change "$(System.DefaultWorkingDirectory)/_{project name}" to "$(System.DefaultWorkingDirectory)\_{project name}" to see if it can work. Or try other agents.

    However, I tested on my side and everything is working fine. The specified working directory can be correctly recognized.

    • PowerShell Tasks enter image description here

      enter image description here

    • Results: enter image description here

      enter image description here