Set “Path” environment variable during vsts build so it would persist across build tasks specifically vsTest task

余生长醉 提交于 2019-12-07 02:14:57

问题


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?


回答1:


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

For example:

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



回答2:


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



来源:https://stackoverflow.com/questions/49288558/set-path-environment-variable-during-vsts-build-so-it-would-persist-across-bui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!