9
votes

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 ps\cmd 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?

2
Environment variables are usually inherited by sub-processes, but processes that are invoked in succession won't be able to pick up the values that way. You may be able set a file that can be queried in your later test task to get the PATH you need.Bob Dalgleish

2 Answers

12
votes

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

For example:

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

If you need to do this in a Linux pipeline you can do the following:

- script: echo "##vso[task.setvariable variable=PATH]${PATH}:<your new path here>"