0

I am using Azure DevOps Deployment Group Agent to deploy Azure DevOps Releases Tasks.

Is there a way to utilize Azure DevOps built-in variables, such as $(System.DefaultWorkingDirectory), within PowerShell files when executing them through the Azure DevOps Releases task, akin to their accessibility when using inline PowerShell within the same task?

Background of the issue:

The issue is that when I run Inline Powershell scripts, it works fine. But when I move the same script to a file and try to consume the file from the repo that is located in $(System.DefaultWorkingDirectory) which is the agent host server, it can not find it.

0

1 Answer 1

2

When you run Azure DevOps built-in variables like $(System.DefaultWorkingDirectory) via a file on an on-prem agent, you need to add $env before the variable. Here's an example of how you can access $(System.DefaultWorkingDirectory) in a PowerShell file:

$workingDirectory = $env:System_DefaultWorkingDirectory
Write-Host "Working Directory: $workingDirectory"

$env is valid and also applies to other Azure DevOps build-in variables in PowerShell when running in the same context.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.