Situation:
I'm currently working on automating CI/CD configurations through bitbucket -> vsts -> azure.
My ideal result is to be able to copy paste (or manually enter) my configuration values into their respective console programs and have the applications configure the whole CI/CD ordeal without having to click through all the web interfaces. It's now possible in Bitbucket and Azure, but creating the VSTS CI/CD configurations through REST API is proving to be difficult.
Azure resources and Bitbucket configurations are currently created through a simple .NET console application that talks to the REST APIs. Basically copy paste (or manually enter) all the values (azure input values / bitbucket input values)into the console application and it will configure everything within 5 minutes.
Problem:
Now I face the harder part of trying to automate build configurations and release configurations in VSTS. Microsoft Docs isn't great on the documentation of VSTS client libraries.
I'm honestly at a loss for how I can create a build definition through the API or Client Library.
The BuildHttpClient has three methods I can work with:
public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, Guid project, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken)); public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken)); public virtual Task<BuildDefinition> CreateDefinitionAsync(BuildDefinition definition, string project, int? definitionToCloneId = null, int? definitionToCloneRevision = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken));
The BuildDefinition has the following properties.
namespace Microsoft.TeamFoundation.Build.WebApi { [DataContract] public class BuildDefinition : BuildDefinitionReference { public BuildDefinition(); public List<string> Tags { get; } public PropertiesCollection Properties { get; } public List<RetentionPolicy> RetentionRules { get; } public List<Demand> Demands { get; } public IDictionary<string, BuildDefinitionVariable> Variables { get; } public List<BuildTrigger> Triggers { get; } public ProcessParameters ProcessParameters { get; set; } public BuildRepository Repository { get; set; } public List<BuildOption> Options { get; } public List<BuildDefinitionStep> Steps { get; } public bool BadgeEnabled { get; set; } public int JobTimeoutInMinutes { get; set; } public BuildAuthorizationScope JobAuthorizationScope { get; set; } public string DropLocation { get; set; } public string Description { get; set; } public string Comment { get; set; } public string BuildNumberFormat { get; set; } public Build LatestBuild { get; } public Build LatestCompletedBuild { get; } } }
As you can see, the most important properties of a build definition are read-only.
How do I go about creating a build definition through the REST API? Are there better alternatives to VSTS that will allow me to do this?