Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

In order to automate our deployments, I would like to rebuild an application, based on a given ChangeSetId. Once this build has completed, I want to get the artifacts of the build (the .exe), so we can deploy them. For the sake of the question, I am focussing on the 'Get artifacts from build' part.

For DevOps purposes, I'd like to use PowerShell, since it should be able to access the TFS API libraries and because MS recommends using it.


I've set up Builds in our On-Premise TFS 2015 server (which are working neatly) - and added a VSO task 'Publish artifacts' after this build. So far so good. The published artifacts are to be stored on the Server, which basically means I have to download the artifacts connected to build - every existing build will have its artifacts linked - which is better than a UNC drop in my book.

No comes to my challenge; how do I programmatically access these artifacts, step 3?

1. Get Sources for ChangeSetId

2. MSBuild application with a given configuration

3. Get build Artifacts using PowerShell

4. Deploy to the environment using Release Management (Powershell as well)

1 Answer

0 votes
by (50.2k points)

TFS 2015 comes with the new rest API, and it includes the method to get the artifacts of the specific build. Approach to your challenge would be in the following way:


After publish artifacts add a power shell script 

In that PowerShell script:

Get the ID of the current build. 

TFS exposes many predefined variables, and build ID is there. All those variables end up as an environment variable

Next, make a web request to get build artifacts. As you can see from the API description, you'll have to provide just the build ID

Then, parse the JSON response - the downloadUrl property contains the link to download all the artifacts of the build zipped as a single archive

Finally, extract the archive and pick up those artifacts you need.

In this step, you can deploy it to your testing environment as well.

Browse Categories