Пример #1
0
        public ReleaseEnvironment UpdateReleaseEnvironment(int releaseId, int targetEnvId, string accessToken)
        {
            if (releaseId < 0)
            {
                throw new ArgumentException("id cannot be less than 0", nameof(releaseId));
            }
            if (targetEnvId < 0)
            {
                throw new ArgumentException("id cannot be less than 0", nameof(targetEnvId));
            }
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentException("parameter cannot be null or whitespace", nameof(accessToken));
            }

            this.logger.LogDebug($"updating release environment. release id:[{releaseId}], target environment id:[{targetEnvId}]");

            ReleaseHttpClient client = this.GetClient <ReleaseHttpClient>(accessToken);

            ReleaseEnvironmentUpdateMetadata environmentMetadata = new ReleaseEnvironmentUpdateMetadata()
            {
                Status  = EnvironmentStatus.InProgress,
                Comment = DeployMessage
            };

            return(client.UpdateReleaseEnvironmentAsync(
                       environmentMetadata,
                       this.vstsConfig.ProjectName,
                       releaseId,
                       targetEnvId).Result);
        }
Пример #2
0
        static ReleaseEnvironment DeployAnEnvironment(ReleaseHttpClient rmClient, int releaseId, int environmentIdToDeploy)
        {
            ReleaseEnvironmentUpdateMetadata envMetaData = new ReleaseEnvironmentUpdateMetadata();

            envMetaData.Status  = EnvironmentStatus.InProgress;
            envMetaData.Comment = "Good to go";
            return(rmClient.UpdateReleaseEnvironmentAsync(envMetaData, projectName, releaseId, environmentIdToDeploy).Result);
        }
        public async Task StartEnvironmentDeployment(VstsRelease vstsRelease, int releaseEnvironmentId)
        {
            ReleaseHttpClient releaseClient = _vssConnection.GetClient <ReleaseHttpClient>();

            ReleaseEnvironmentUpdateMetadata releaseEnvironmentUpdateMetadata = new ReleaseEnvironmentUpdateMetadata()
            {
                Status = EnvironmentStatus.InProgress
            };

            await releaseClient.UpdateReleaseEnvironmentAsync(releaseEnvironmentUpdateMetadata, _configuration.Value.ProjectName, vstsRelease.Id, releaseEnvironmentId);
        }
Пример #4
0
 static void CancelAllInProgressDeployments(ReleaseHttpClient rmClient)
 {
     try
     {
         var allInProgressEnvironments = rmClient.GetDeploymentsAsync(
             projectName,
             deploymentStatus: DeploymentStatus.InProgress).Result;
         foreach (var inProgressEnvironment in allInProgressEnvironments)
         {
             ReleaseEnvironmentUpdateMetadata envMetaData = new ReleaseEnvironmentUpdateMetadata();
             envMetaData.Status  = EnvironmentStatus.Canceled;
             envMetaData.Comment = "Good to cancel";
             var cancelledEnvironment = rmClient.UpdateReleaseEnvironmentAsync(
                 envMetaData,
                 projectName,
                 inProgressEnvironment.Release.Id,
                 inProgressEnvironment.ReleaseEnvironment.Id).Result;
         }
     }
     catch (Exception)
     {  }
 }
Пример #5
0
        public WebApiRelease StartDeployment()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

            // Get a release client instance
            VssConnection     connection    = Context.Connection;
            ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>();

            WebApiRelease release = CreateRelease(releaseClient, newlyCreatedReleaseDefinitionId, projectName);

            ReleaseEnvironmentUpdateMetadata releaseEnvironmentUpdateMetadata = new ReleaseEnvironmentUpdateMetadata()
            {
                Status = EnvironmentStatus.InProgress
            };

            int releaseEnvironmentId = release.Environments.FirstOrDefault().Id;

            // Start deployment to an environment
            ReleaseEnvironment releaseEnvironment = releaseClient.UpdateReleaseEnvironmentAsync(releaseEnvironmentUpdateMetadata, projectName, release.Id, releaseEnvironmentId).Result;

            Console.WriteLine("{0} {1}", releaseEnvironment.Id.ToString().PadLeft(6), releaseEnvironment.Name);

            return(release);
        }