5
votes

I want to be able to display a directory path of the Artifact in the PowerShell task in the Release pipeline. In the build pipeline, the directory of the Artifact is described by the variable $(System.DefaultWorkingDirectory) and if I try to display it in the PowerShell task using the command

Write-Host $(System.DefaultWorkingDirectory)

in the console output, it shows the path C:\agent\_work\3\a. This variable doesn't exist in the Release pipeline and when I run the command

Get-ChildItem Env:

in the powerhsell task, in the release pipeline, I can see all environemnt variables but none of the variables stores the C:\agent\_work\3\a path How can i get it, cuz somehow the AgentJob knows the proper directory of the Artifact when doing the Artifact downloading process. Any ideas? Cheers

1
Based on the documentation, I'd expect that variable to be available in a release pipeline. It should be the same as $Agent.ReleaseDirectory or $System.ArtifactsDirectoryMatt

1 Answers

5
votes

When accessing build and release variables as environment variables within scripts, you need to replace . with _. This is explained in the documentation. In PowerShell, you'd access $env:SYSTEM_DEFAULTWORKINGDIRECTORY.

Variable names are transformed to uppercase, and the characters "." and " " are replaced by "_".

For example, Agent.WorkFolder becomes AGENT_WORKFOLDER. On Windows, you access this as %AGENT_WORKFOLDER or $env:AGENT_WORKFOLDER. On Linux and macOS, you use $AGENT_WORKFOLDER.