public static WebApiRelease CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName, Dictionary <string, ConfigurationVariableValue> overrideVaraibles = null) { BuildVersion instanceReference = new BuildVersion { Id = "2" }; ArtifactMetadata artifact = new ArtifactMetadata { Alias = "Fabrikam.CI", InstanceReference = instanceReference }; ReleaseStartMetadata releaseStartMetaData = new ReleaseStartMetadata(); releaseStartMetaData.DefinitionId = releaseDefinitionId; releaseStartMetaData.Description = "Creating Sample release"; if (overrideVaraibles != null) { // If you want to override varaibles at release create time, 'AllowOverride' on variable should be set while creating RD. // You can override environment level variables using releaseStartMetaData.EnvironmentsMetadata.Variables. releaseStartMetaData.Variables = overrideVaraibles; } releaseStartMetaData.Artifacts = new[] { artifact }; // Create a release WebApiRelease release = releaseClient.CreateReleaseAsync(project: projectName, releaseStartMetadata: releaseStartMetaData).Result; return(release); }
/// <inheritdoc /> public async Task <Release> CreateReleaseAsync(string account, string teamProject, int definitionId, OAuthToken token) { account.ThrowIfNullOrWhiteSpace(nameof(account)); teamProject.ThrowIfNullOrWhiteSpace(nameof(teamProject)); definitionId.ThrowIfSmallerOrEqual(nameof(definitionId)); token.ThrowIfNull(nameof(token)); ReleaseDefinition definition; using (var client = await this.ConnectAsync <ReleaseHttpClient2>(token, account)) { definition = await client.GetReleaseDefinitionAsync(teamProject, definitionId); } var metadatas = new List <ArtifactMetadata>(); using (var client = await this.ConnectAsync <BuildHttpClient>(token, account)) { foreach (var artifact in definition.Artifacts.Where(a => string.Equals(a.Type, ArtifactTypes.BuildArtifactType, StringComparison.OrdinalIgnoreCase))) { var definitions = new List <int> { Convert.ToInt32(artifact.DefinitionReference["definition"].Id) }; var builds = await client.GetBuildsAsync2(teamProject, definitions); var build = builds.OrderByDescending(b => b.LastChangedDate).FirstOrDefault(); if (build == null) { continue; } var metadata = new ArtifactMetadata { Alias = artifact.Alias, InstanceReference = new BuildVersion { Id = build.Id.ToString() } }; metadatas.Add(metadata); } } using (var client = await this.ConnectAsync <ReleaseHttpClient2>(token, account)) { var metaData = new ReleaseStartMetadata { DefinitionId = definitionId, Artifacts = metadatas }; return(await client.CreateReleaseAsync(metaData, teamProject)); } }
private static WebApiRelease CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName) { BuildVersion instanceReference = new BuildVersion { Id = "2" }; ArtifactMetadata artifact = new ArtifactMetadata { Alias = "Fabrikam.CI", InstanceReference = instanceReference }; ReleaseStartMetadata releaseStartMetaData = new ReleaseStartMetadata(); releaseStartMetaData.DefinitionId = releaseDefinitionId; releaseStartMetaData.Description = "Creating Sample release"; releaseStartMetaData.Artifacts = new[] { artifact }; // Create a release WebApiRelease release = releaseClient.CreateReleaseAsync(project: projectName, releaseStartMetadata: releaseStartMetaData).Result; return(release); }
private static async Task <Release> CreateReleaseAsync(Build build, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var releaseClient = ProjectCollection.GetClient <ReleaseHttpClient>(); var releaseDefinition = (await releaseClient.GetReleaseDefinitionsAsync(Options.TFSProjectName, ReleaseDefinitionName, cancellationToken: cancellationToken)).FirstOrDefault(); if (releaseDefinition == null) { Log.Error($"Could not find a release definition with name: {ReleaseDefinitionName}"); return(null); } var releaseMetadata = new ReleaseStartMetadata() { DefinitionId = releaseDefinition.Id, Description = $"Automated release for {Options.BranchName} for build {build.BuildNumber}", Reason = ReleaseReason.ContinuousIntegration }; var artifactMetadata = new ArtifactMetadata { Alias = "InputBuild", // This is the alias in the Release definition. InstanceReference = new Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Contracts.BuildVersion { Id = build.Id.ToString(CultureInfo.InvariantCulture), Name = build.BuildNumber } }; artifactMetadata.InstanceReference.SourceBranch = build.SourceBranch; releaseMetadata.Artifacts = new List <ArtifactMetadata> { artifactMetadata }; return(await releaseClient.CreateReleaseAsync(releaseMetadata, Options.TFSProjectName, cancellationToken : cancellationToken)); }