1

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.

1
  • 1
    If you want to get build artifacts from release, you can use the variabele $(System.ArtifactsDirectory) instead. The build artifacts located in $(System.ArtifactsDirectory)\{BuildDefinitionName}\{ArtifactsName} (such as $(System.ArtifactsDirectory)\ASP.NET\Drop). Commented Feb 22, 2018 at 2:50

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm trying to read a file that's in my artifact but it is not in the same directory my script is located.
So your powershell script should take this value in as an argument, in a build, you set the argument to what is currently working, for a release, you piece it together based on the release/artifact variables, e.g. start at "System.ArtifactsDirectory" and locate the file within the artifact
1

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.