Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 652
uril Avatar asked Mar 14 '18 22:03

uril


People also ask

How do I set the path on my azure pipeline?

To permanently add the directory to environment variable PATH so that it can work for next others steps, you need use setx or add them into Registry by using reg add . But the usage of setx has limitation that the PATH value max to 1024 characters.

How do you set variables in Azure pipeline?

setvariable , the following tasks can use the variable using macro syntax $(myVar) . The variable will only be available to tasks in the same job by default. If you add the parameter isoutput , the syntax to call your variable changes. See Set an output variable for use in the same job.

Where is build SourcesDirectory defined?

$(Build. SourcesDirectory) : The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.


2 Answers

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

For example:

Write-Host "##vso[task.setvariable variable=PATH;]${env:PATH};$newPath";
like image 39
starian chen-MSFT Avatar answered Sep 23 '22 05:09

starian chen-MSFT


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>"

like image 173
Jonathan Chauncey Avatar answered Sep 19 '22 05:09

Jonathan Chauncey