Esempio n. 1
0
        public IEnumerable <Release> GetReleases(
            int definitionId,
            string accessToken,
            int?artifactVersionId = null,
            int?prereqEnvId       = null)
        {
            if (definitionId < 0)
            {
                throw new ArgumentException("id cannot be less than 0", nameof(definitionId));
            }
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentException("parameter cannot be null or whitespace", nameof(accessToken));
            }

            this.logger.LogDebug($"getting releases. definitionId:[{definitionId}], artifaction version id:[{artifactVersionId}], prereq environment id:[{prereqEnvId}]");

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

            bool hasArtifactVersionId    = artifactVersionId.HasValue && artifactVersionId > 0;
            bool hasPrereqEnvId          = prereqEnvId.HasValue && prereqEnvId > 0;
            int? environmentStatusFilter = this.GetEnvironmentStatusFilter();

            return(client.GetReleasesAsync(
                       this.vstsConfig.ProjectName,
                       definitionId,
                       statusFilter: ReleaseStatus.Active,
                       artifactVersionId: hasArtifactVersionId ? artifactVersionId.ToString() : null,
                       definitionEnvironmentId: prereqEnvId,
                       environmentStatusFilter: hasArtifactVersionId ? environmentStatusFilter : (int?)null,
                       expand: ReleaseExpands.Artifacts).Result);
        }
Esempio n. 2
0
        public WebApiRelease UpdateRelease()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

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

            List <WebApiRelease> releases = releaseClient.GetReleasesAsync(project: projectName).Result;
            int releaseId = releases.FirstOrDefault().Id;

            WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result;

            IDictionary <string, ConfigurationVariableValue> varaibles = release.Variables;

            varaibles.Add(
                new KeyValuePair <string, ConfigurationVariableValue>("System.Debug", new ConfigurationVariableValue
            {
                AllowOverride = true, IsSecret = false, Value = "false"
            }
                                                                      )
                );

            // Update the release
            WebApiRelease updatedRelease = releaseClient.UpdateReleaseAsync(release: release, project: projectName, releaseId: releaseId).Result;

            Context.Log("{0} {1}", release.Id.ToString().PadLeft(6), updatedRelease.Name);

            return(release);
        }
Esempio n. 3
0
        static void GetWorkItemsForARelease(ReleaseHttpClient rmClient, int currentReleaseId)
        {
            var currentRelease = rmClient.GetReleaseAsync(project: projectName, releaseId: currentReleaseId).Result;
            var definitionId   = currentRelease.ReleaseDefinition.Id;
            var lastTwoRelease = rmClient.GetReleasesAsync(
                project: projectName,
                definitionId: definitionId,
                continuationToken: currentReleaseId,
                top: 2,
                queryOrder: ReleaseQueryOrder.Descending).Result;

            var baseReleaseId = lastTwoRelease[1].Id;

            var workItems = rmClient.GetReleaseWorkItemsRefsAsync(project: projectName, releaseId: currentReleaseId, baseReleaseId: baseReleaseId).Result;
        }
 public Task <List <Release> > GetReleasesAsync(
     string project,
     int?definitionId             = null,
     int?definitionEnvironmentId  = null,
     int?environmentStatusFilter  = null,
     ReleaseQueryOrder?queryOrder = null,
     int?top = null,
     ReleaseExpands?expand     = null,
     string artifactId         = null,
     string sourceBranchFilter = null)
 {
     return(_client.GetReleasesAsync(project, definitionId,
                                     definitionEnvironmentId, null, null, null,
                                     environmentStatusFilter,
                                     null, null, queryOrder, top, null, expand, null, artifactId, null, sourceBranchFilter));
 }
Esempio n. 5
0
        public WebApiRelease GetRelease()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

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

            List <WebApiRelease> releases = releaseClient.GetReleasesAsync(project: projectName).Result;

            int releaseId = releases.FirstOrDefault().Id;

            // Show a release
            WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result;

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

            return(release);
        }
Esempio n. 6
0
        /// <summary>
        /// View top 10 releases
        /// </summary>
        /// <param name="teamProjectName"></param>
        /// <param name="reldefId"></param>
        private static void ViewReleases(string teamProjectName, int reldefId)
        {
            var rels = ReleaseClient.GetReleasesAsync(teamProjectName, reldefId, expand: ReleaseExpands.Environments, top: 10).Result;

            foreach (var rel in rels)
            {
                Console.WriteLine("-----------RELEASE---------------------------------------------");
                Console.WriteLine("ID: {0} REASON: {1} NAME: {2}", rel.Id, rel.Reason, rel.Name);
                Console.WriteLine("---------------------------------------------------------------");
                Console.WriteLine("STAGES:");

                if (rel.Environments != null)
                {
                    foreach (var env in rel.Environments)
                    {
                        Console.Write(env.Name + " : " + env.Status + "; ");
                    }
                }

                Console.WriteLine();
                ViewBuildArtifacts(teamProjectName, rel.Id);
            }
        }
Esempio n. 7
0
        public System.IO.Stream GetLogsOfReleaseTask()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

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

            // Get Release Defintion
            ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result;

            // Get all completed environment releases.
            // environmentStatusFilter values Undefined = 0,  NotStarted = 1, InProgress = 2, Succeeded = 4, Canceled = 8, Rejected = 16, Qeued = 32, Scheduled = 64, PartiallySucceeded = 128
            List <WebApiRelease> releases = new List <WebApiRelease>();

            ClientSampleHelpers.Retry(
                TimeSpan.FromMinutes(2),
                TimeSpan.FromSeconds(5),
                () =>
            {
                releases = releaseClient.GetReleasesAsync(project: projectName, definitionId: releaseDefinition.Id, definitionEnvironmentId: releaseDefinition.Environments.First().Id, expand: ReleaseExpands.Environments, environmentStatusFilter: 4).Result;
                return(releases.Count > 0);
            });

            // Get first release first environment first deployment first task log
            WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releases.First().Id).Result;

            this.completedReleaseId = release.Id;
            ReleaseEnvironment releaseEnvironment = release.Environments.First();
            ReleaseDeployPhase deployPhase        = releaseEnvironment.DeploySteps.First().ReleaseDeployPhases.FirstOrDefault();
            ReleaseTask        task = deployPhase.DeploymentJobs.First().Tasks.First();

            System.IO.Stream taskLog = releaseClient.GetTaskLogAsync(project: projectName, releaseId: release.Id, environmentId: releaseEnvironment.Id, releaseDeployPhaseId: deployPhase.Id, taskId: task.Id).Result;
            Context.Log("{0} {1}", release.Id.ToString().PadLeft(6), release.Id);

            return(taskLog);
        }
 public async Task <List <Release> > GetReleases()
 {
     return(await _client.GetReleasesAsync(Credentials.PROJECT));
 }