0
votes

In a custom vsts build task I want to know the path to the current build pipeline so that I can reuse the path to automatically calculate the path to the build drop folder.

In the vsts build portal where I create build pipelines they can be organized into folders. It's this folder path that I need to use in the build task. I can get hold of the name of the build pipeline from variables here: https://docs.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts&tabs=batch

But, there's no variable for the folder name. How can I get the folder name?

2

2 Answers

1
votes

The folder that the build definition lives under is purely a build definition thing -- it has no bearing on a running build, so it's not populated as a build-time variable.

You can retrieve the build definition by making a REST API call: GET https://{accountName}.visualstudio.com/{project}/_apis/build/definitions/{definitionId}?api-version=4.1. The account URI and build definition ID are available in a running build, and you can easily allow your script access to an OAuth token (populated in the SYSTEM_ACCESSTOKEN environment variable) for authentication purposes.

This will return a JSON object, which contains a path property. That's the path to your build definition.

0
votes

You must be using an agent for your build pipeline. The agent may be hosted on VSTS or it may be on your premises.

Now, all the tasks in build definitions are executed on agent. Agent is simply a machine. Normally it uses below folders during build process.

  • Build.Repository.LocalPath or Build.SourcesDirectory or System.DefaultWorkingDirectory = c:\agent_work\1\s : The local path on the agent where your source code files are downloaded
  • Build.ArtifactStagingDirectory or Build.StagingDirectory = c:\agent_work\1\a: The local path on the agent where any artifacts are copied to before being pushed to their destination.

So answer your question:

  1. c:\agent_work\1\s here source code is downloaded.
  2. c:\agent_work\1\a here you can copy anything. Build definition uses this path to generate build artifacts at the end of build.