2
votes

I am using TFS 2018 on premise with a TFVC project. When I create a new build using the “Empty process” template, the “Get sources” task is automatically added as the first step. This task always gets the latest sources by specifying the latest changeset number on the command line at run time: “tf vc get /version:{latest changeset number}”. I know that the agent variable “Build.SourceVersion” is available and contains the value of the {latest changeset number}. I also know that when I queue the build I can specify the "Build.SourceVersion” for the “Get sources” task in the “Source version” field.

How can I specify the “Source version” in the build definition?

How can I override the "Build.SourceVersion” variable used by the “Get sources” task?

I have tried to specify the "Build.SourceVersion” variable on the “Variables” tab of the build definition but it appears to have no effect.

Update: I created a User Voice request for this: https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/32746480-allow-source-version-to-be-specified-in-the-get

2
What are you trying to accomplish? You can specify a changeset when queuing the build.Daniel Mann
I dont see a straight forward way to do this however, you can use a cmd as the first task in your build definition and run. <path to tf>\tf.exe vc get /version:{changeset number you need to get}Dhruv Patel

2 Answers

1
votes

You could only specify source version in queue build dialog, otherwise the build agent will auto pick the latest version.

It's not able to directly override the "Build.SourceVersion” variable used by the “Get sources” task through build definition.

As a workaround, you could add a variable Build.SyncSources = false to disable the system Get Sources step in vNext build. Detail steps please follow my reply in this link: Is it able to ignore/disable the first step Get source in vNext Build?

Then just do a Get sources from TFS using a custom PowerShell or batch script with TF.exe command line tool by yourself.

0
votes

This may not be the best solution; but you can select “Don’t sync sources” on the default Get Sources process and manually grab the source using a power shell script that passes the source version as an argument which can then be a variable set through TFS