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?
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.
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.
$(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.
Set the process environment variable by calling logging command through PowerShell task:
For example:
Write-Host "##vso[task.setvariable variable=PATH;]${env:PATH};$newPath";
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>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With