Is it possible to nest TFS build template arguments in one another?
Example (Set via build definition ui):
$(ToolsRoot) = E:\BuildTools
$(MSPECTools) = $(ToolsRoot)\MSpec\
Alternatively, is it possible to use environmental variables.
I have tried both, and neither seemed to work.
I need to find a way of setting the build root dynamically, as it differs on our various build servers.
I suppose you have implemented a topology like the this:
So, you need to control the root for each Agent.If you open the TFS Admin Console > Build configuration in Build Machine #1 you 'll see the Build Controller & Agents A.1 & A.2.If you open TFS Admin Console > Build configuration in Build Machine #2 you 'll see Agents A.3, A.4, A.5 & A.6.
For any given build Agent, if you click on "Properties" you 'll see the "Working Directory" entry, which typically is set to something like $(SystemDrive)\Builds\$(BuildAgentId)\. On runtime this is transformed into something like C:\Builds\55.
For any given build, in the build definition area "Workspaces" this "Working Directory" equals the entry $(SourceDir).
Suppose you have set in Agent A.1 a working directory "C:\A.1\Build" & in Agent A.2 "C:\A.2\Build". In order to get what you need, you have to set in the build definition a mapping to $(SourceDir)\Template
Related
I want to get the number inside the _work folder of an on-premise TFS agent.
For example:
From C:/agent/_work/1 get the 1.
Is there a variable to get the 1 part?
You can use a small PowerShell script to extract the number and set a new variable for the sequences steps:
$folderPath = "$env:Agent_BuildDirectory"
$folderNumber = $folderPath.Split('\')[$folderPath.Split('\').Count - 1]
Write-Host "##vso[task.setvariable variable=folderNumber]$folderNumber"
Now you can use the variable $(folderNumber) in the sequences tasks.
There is no reason for you to parse this information out. The current working folder for a given build or release is accessible in the variable $(Agent.BuildDirectory).
If you are trying to reference the working folder of a different build, then you are doing something wrong with your build process, and there are a number of different, valid solutions to that problem.
Check out the different variable values and ways to customize them if needed. Note the Agent.DeploymentGroupId is is not something you would change.
Release variables and debugging
Agent.DeploymentGroupId
The ID of the deployment group the agent is registered with. This is available only in deployment group jobs.
Example: 1
Agent.WorkFolder
The working directory for this agent, where subfolders are created for every build or release. Same as Agent.RootDirectory and System.WorkFolder.
Example: C:\agent_work
I have to customize TFS DefaultTemplate.xaml with MSBuildArguments Parameter.
Once we try to create new XAML build definition & select default template, once it gets loaded then I want to set code MSBuildArguments in Advance setting & parameter should be /p:DebugType=pdbOnly;Configuration=Release by default.
As of now this Arguments we have to put manually whenever we create a new build definition. I want to make it customize this template.
screen shot:
Specify MSBuild Arguments when create a build definition or queue a build is more convenient.
However if you want to bind the arguments with the xaml build template, then you need to custom the template.
In your scenario, you can simply replace the value of CommandLineArguments with below strings: (Note that the arguments you added here will be hidden, that means you can not see them in build definition, they are set to be the default arguments)
String.Format("/p:SkipInvalidConfigurations=true {0}", "/p:DebugType=pdbOnly;Configuration=Release").
But same time the MSBuildArguments you specified in build definition will not be available any more.
You can reference below articles to custom the build template to replace the MSBuildArguments:
Pass Relative Path Arguments to MSBuild in TFS2010 Team Build
Properly incorporate MsBuild arguments into your build process
template
I have a TFS 2017 build that was setup with multi-Configuration that has a multiplier of BuildConfiguration. This worked fine with until I took all the build steps and moved them into a Task Group. Now I get an error that seems to indicate that it's looking at the full string of the variable BuildConfiguration dev,int verses iterating over it. Does this not work with Task Groups?
Based on my test, Multi-Configuration is not available for Task Group.
When you select all the build steps and create a TaskGroup, you need to set Multi values (eg : Release,Debug) for the buildConfiguration.
But during the build it will meet this error message :"Error MSB4126: The specified solution configuration "Release,debug|Any CPU" is invalid"
To correct that error, you need to set it as unique value (eg :Release ) or leave it as empty. Thus the build works, but actually it's not the real Multi-Configuration build even though it displays Release and Debug there. (You can check the build log for the "Multi" builds, you will see the actual msbuild command with argument )
I have submitted a feedback here for this issue, hope achieve it in future.
I figured out how to make it work.
My problem was the BuildConfiguration variable that gets created in the Task Group has to be set to refer back to the BuildConfiguration variable at the Build level (may be using the wrong term here...).
So instead of setting the Task Group var to dev,int I had to set it to $(BuildConfiguration) which refers it back.
So my task group variables look like this (I highlighted the BuildConfiguration var that was my issue):
I thought this would be pretty straight forward, but it looks like the template has to be modified. Anyone have any idea what to do to add this piece to the default template?
I know how to edit the templates, I just don't know what I need to do to make this work.
This case already provided a solution for your requirement:
Copy the DefaultTemplate.xaml to DefaultTemplateCustom.xaml and open it
Click the Collapse All link in the top right corner
Open the toolbox and locate the Assign activity. It is located in the Primitives section
Drag the Assign activity to the end of the workflow, after the "Run MSBuild" activity
Go to the properties window. Set the "To" parameter to BuildDetail.Quality. Set "Value" to "xxx (Build Quality)"
Locate the InvokeMethod in the toolbox and drag it and drop it after the Assign activity
Set the "Target Object" to BuildDetail. Set "MethodName" to Save
Save the build definition xaml file and check it in, then build with the customized definition.
You can also consider to create a powershell script to set the build quality via TFS API and then invoke this powershell script in your build template. Refer to this link for details: PowerShell and TFS: The Basics and Beyond.
Here is a simple script to set the build quality:
$builduri = "vstfs:///Build/Build/1";
$collectionurl = "http://xxxx:8080/tfs/xxx/";
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($collectionurl);
$buildservice = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]);
$build = $buildservice.GetBuild($builduri);
$build.Quality = "Released";
$build.Save()
For my Team Build process, I have created Work Flow activities that control deployment. I want to choose at runtime whether to deploy the build.
So, I need to send Deploy=true or false as an input to the work flow runtime initiation.
I can do this by defining a Work Flow custom metadata value with an internal argument. I can then set the Deploy value at runtime via the Queue Build dialog under the Parameters tabs.
My question is: How do I specify my custom variable when starting a TFS build from the command line with tfsbuild.exe start?
The command line parameter is called /msBuildArguments
TfsBuild start teamProjectCollectionUrl teamProject definitionName
[/dropLocation:dropLocation] [/getOption:getOption]
[/priority:priority] [/customGetVersion:versionSpec]
[/requestedFor:userName] [/msBuildArguments:args] [/queue]
[/shelveset:name [/checkin]] [/silent]
You can use: tfsbuild start http://yourserver:8080/tfs/ YourProject YourBuild Definition /msBuildArguments:"Deploy=true"