Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

azure devops - Set "Path" environment variable during vsts build so it would persist across build tasks specifically vsTest task

I have a vsts build definition in which I try to set the PATH environment variable using PowerShell (and before I tried cmd) task, so that in a later vsTest task, the tests could run an exe from that path, however setting the PATH using the pscmd tasks doesn’t seem to work, I tried a few options such as:

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";" + $newPath, [EnvironmentVariableTarget]::User)

setx path " %newPath;%PATH%"

Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Set the process environment variable by calling logging command through PowerShell task:

For example:

Write-Host "##vso[task.setvariable variable=PATH;]${env:PATH};$newPath";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...