Reputation: 27
Using the Microsoft.TeamFoundation.Build.Client I am able to create an instance of the IBuildServer and from there create a new build definition.
What I am struggling with is how to set the trigger for the build to be scheduled and to set the time.
If I retrieve an existing build that is set to Scheduled Trigger all I can see is a build property called TriggerType which is set to ScheduleForced. None of the other information seems to be available i.e. time, days, build if nothing has changed flag.
Any thoughts where these properties are set? Perhaps on the build controller?
Upvotes: 2
Views: 756
Reputation: 29976
You can use following properties to set the build schedule:
IBuildServer IBS = tpc.GetService<IBuildServer>();
IBuildDefinition ibdef = IBS.CreateBuildDefinition(projectname);
ibdef.Name = "ApiDef";
ibdef.TriggerType = DefinitionTriggerType.ScheduleForced;
ISchedule iss = ibdef.AddSchedule();
iss.DaysToBuild = ScheduleDays.Friday;
iss.StartTime = 10800;
iss.TimeZone = TimeZoneInfo.Utc;
ibdef.Save();
Upvotes: 2
Reputation: 31083
Couldn't find any TFS API to trigger a scheduled build. Instead of API, after creating a build definition with API, you can create a batch file and a task schedule for scheduling the builds.
As we can use TFSBuild start command to run a configured build definition for Team Foundation Build, command is as below:
TFSBuild start /collection:teamProjectCollectionUrl /builddefinition:definitionSpec
So we use this command to create a batch file, for example, batchbuild.bat, and file content looks like:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TFSBuild" start /collection:http://tfsserver:8080/tfs/DefaultCollection /builddefinition:teamproject\builddefinition
Then schedule a task for running the build command at regular intervals as required by your project.
Upvotes: 0