Question How can we schedule a pipeline for a later time using Azure Devops .net sdk services in our c# web api?

destro

Well-known member
Joined
Mar 28, 2020
Messages
46
Programming Experience
1-3
Hello,
I am working with Microsoft.VisualStudio.Services.WebApi & Microsoft.TeamFoundation.Build.WebApi. I can trigger pipeline using buildClient.QueueBuildAsync(build).Wait(); but unable to find a way to schedule a pipeline for a later time. Can you please point us in the right direction?

Thanks in advance
 
The point of doing CI/CD is to have as fast throughput as possible from checkin to deployment. Why would you want to put any delays into that by delaying the build? Continuous integration is supposed to give you a build as soon as new code is checked in so that you can run tests as soon as possible, so that you can tell if that new code broke something. So you want to check in code today, but not build it until after you leave for vacation and let your co-workers deal with the broken build?
 
@Skydiver Thanks for the response.

I undestand your point and we have continuous integration applied to our Pipeline but our client is asking that we make a feature for scheduling these pipelines as well. We did it all through Team Foundation and Visual Studio service api in a c# api but struggling to schedule the pipeline.

Please help
 
I can see abstract class BuildTrigger in Microsoft.TeamFoundation.Build.WebApi that contains property DefinitionTriggerType enum with schedule or 8 number. but how can I implement it to my pipeline before queuing?

This is how I run pipeline:

Run Pipeline:
var credential = new VssBasicCredential(string.Empty, patToken);
var connection = new VssConnection(new Uri("https://dev.azure.com/eliteTeam4991/"), credential);
var buildClient = connection.GetClient<BuildHttpClient>();
var projectClient = connection.GetClient<ProjectHttpClient>();
projectClient.GetProjects();
var project = projectClient.GetProject(projectName).Result;
Console.WriteLine(project.Name);



var definition = buildClient.GetDefinitionAsync(projectName, userSelectedPipelineID).Result;



Console.WriteLine(definition.Name);



                          var build = new Build()
                         {
                             Definition = definition,
                             Project = project,
                         };`


//Runs Pipeline
buildClient.QueueBuildAsync(build).Wait();
Console.WriteLine(string.Format("Pipeline {0} started running successfully", definition.Name));
 
Last edited:
The following link is for data factory pipelines, but I would not be surprised if a very similar approach is done for build pipelines:
 
I cant use Azure Data Factory. The api mentioned in this article is not using azure devops services .net sdk.
I don't have active directory access in my organization.
 
The triggers made using data factory requires active directory access. We don't have that. We are creating triggers using TeamFoundation.Build api like so:
Create schedule trigger using TeamFoundation.Build.WebApi:
 //Create Trigger
                        ScheduleTrigger trigger = new ScheduleTrigger();
                      
                        //Create Schedule
                        Schedule schedule = new Schedule();
                        schedule.StartHours = 10;
                        schedule.StartMinutes = 00;

                        //Add schedule to trigger in a list

                        trigger.Schedules = new List<Schedule>();
                        trigger.Schedules.Add(schedule);

but unable to set it in the definition:
1672922287101.png

TriggerTypes have only getters no setters.
 
If I were in your shoes, instead of trying to update an existing definition, I would first try to create a simple scheduled build definition from scratch. If that succeeds, then at least I have a path forward by creating new build definitions by copying over the contents of old build definitions into the new one.
 
Back
Top Bottom