简体   繁体   中英

Powershell script running in vsts release not recognizing environment variables

I've created a VSTS build with an Azure PowerShell script that works perfectly. The issue comes when I try to call the exact same script (exact same file in a git repo) from my VSTS release. When the script runs I get no errors but the environment variable, $Env:BUILD_SOURCESDIRECTORY , is empty. Like I've said before the VSTS build executes perfectly but I'm unable to run the exact same code in a VSTS release.

Your problem is that you are using a Build variable inside a Release . This just isn't going to work, it's empty because it simply doesn't exist in a release context.

Even if you could do this, I wouldn't suggest you do this. Your release should rely solely on artifacts, not build variables when the artifact was generated. You could certainly define this variable in your artifact, and access from the release, but I would highly suggest you not go down this path, as it's a really bad practice.

You didn't mention it, but if you stated why you think you need access to a build variable, perhaps we could help you find a better solution here.

Not all variables that are available in Build are available in Release. The Sources directory is available during the build. If you want to keep it available during Release, you should create an artefact in the Build, name it Sources. That way the artefact will be available in Release through its respective variables.

Overview of variables available in:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM