コード例 #1
0
        public async Task StartBuildAsync(DisplayBuild build)
        {
            var client = VssClientHelper.GetClient <BuildHttpClient>(
                Settings.GlobalSettings.Current.AccountUrl,
                Settings.GlobalSettings.Current.ApiKey,
                Settings.GlobalSettings.Current.UseSsl);

            await client.QueueBuildAsync(new Microsoft.TeamFoundation.Build.WebApi.Build
            {
                Definition = new DefinitionReference {
                    Id = build.DefinitionId
                }
            }, Settings.GlobalSettings.Current.Project);
        }
コード例 #2
0
ファイル: DeployHelper.cs プロジェクト: vzabrodin/RocketBuild
        public async Task StartDeploymentAsync(DisplayRelease release)
        {
            if (!release.EnvironmentId.HasValue)
            {
                MessageBox.Show($"Release definition '{release.Name}' has no any release. Setup automatic release creation in TFS or create release manually.");
                return;
            }

            var client = VssClientHelper.GetClient <ReleaseHttpClient>(
                Settings.GlobalSettings.Current.AccountUrl,
                Settings.GlobalSettings.Current.ApiKey,
                Settings.GlobalSettings.Current.UseSsl);

            await client.UpdateReleaseEnvironmentAsync(new ReleaseEnvironmentUpdateMetadata
            {
                Status  = EnvironmentStatus.InProgress,
                Comment = "Started from RocketBuild application"
            }, Settings.GlobalSettings.Current.Project, release.Id, release.EnvironmentId.Value);
        }
コード例 #3
0
ファイル: BuildHelper.cs プロジェクト: vzabrodin/RocketBuild
        public async Task <List <DisplayBuild> > GetBuildsAsync()
        {
            var client = VssClientHelper.GetClient <BuildHttpClient>(
                Settings.GlobalSettings.Current.AccountUrl,
                Settings.GlobalSettings.Current.ApiKey,
                Settings.GlobalSettings.Current.UseSsl);

            var tfsClient = VssClientHelper.GetClient <TfvcHttpClient>(
                Settings.GlobalSettings.Current.AccountUrl,
                Settings.GlobalSettings.Current.ApiKey,
                Settings.GlobalSettings.Current.UseSsl);

            List <BuildDefinitionReference> definitions = await client.GetDefinitionsAsync(Settings.GlobalSettings.Current.Project, name : null);

            var tfsBuilds = await client.GetBuildsAsync(Settings.GlobalSettings.Current.Project, definitions : definitions.Select(d => d.Id), maxBuildsPerDefinition : 1, queryOrder : BuildQueryOrder.FinishTimeDescending);

            var builds = new List <DisplayBuild>();

            TfvcChangesetRef changeset = (await tfsClient.GetChangesetsAsync(Settings.GlobalSettings.Current.Project, top: 1)).FirstOrDefault();

            foreach (BuildDefinitionReference definition in definitions)
            {
                var    lastTfsBuild     = tfsBuilds.FirstOrDefault(b => b.Definition.Id == definition.Id);
                string lastTfsBuildLink = (lastTfsBuild?.Links.Links["web"] as ReferenceLink)?.Href;

                builds.Add(new DisplayBuild
                {
                    DefinitionId    = definition.Id,
                    Path            = definition.Path.TrimStart('\\'),
                    Name            = definition.Name,
                    LastBuild       = lastTfsBuild != null ? Regex.Match(lastTfsBuild.BuildNumber, Settings.GlobalSettings.Current.BuildNameExtractVersionRegex).Value : String.Empty,
                    LastBuildStatus = (DisplayBuildStatus?)lastTfsBuild?.Status,
                    LastBuildResult = (BuildResult?)lastTfsBuild?.Result,
                    LastBuildLink   = lastTfsBuildLink,
                    LastCheckin     = changeset?.ChangesetId.ToString()
                });
            }

            return(builds);
        }
コード例 #4
0
ファイル: DeployHelper.cs プロジェクト: vzabrodin/RocketBuild
        public async Task <List <DisplayEnvironment> > GetEnvironmentsAsync()
        {
            var client = VssClientHelper.GetClient <ReleaseHttpClient>(
                Settings.GlobalSettings.Current.AccountUrl,
                Settings.GlobalSettings.Current.ApiKey,
                Settings.GlobalSettings.Current.UseSsl);
            var environments = new List <DisplayEnvironment>();

            List <ReleaseDefinition> definitions = await client.GetReleaseDefinitionsAsync(Settings.GlobalSettings.Current.Project, expand : ReleaseDefinitionExpands.Environments);

            string[] environmentNames = definitions.SelectMany(d => d.Environments).Select(e => e.Name).Distinct().ToArray();

            List <Release> releases = await client.GetReleasesAsync(
                Settings.GlobalSettings.Current.Project,
                expand : ReleaseExpands.Environments,
                // Reduce number of releases to load faster
                minCreatedTime : DateTime.Today.AddMonths(-6));

            foreach (string environmentName in environmentNames)
            {
                var environment = new DisplayEnvironment
                {
                    Name = environmentName
                };

                foreach (ReleaseDefinition definition in definitions)
                {
                    ReleaseDefinitionEnvironment definitionEnvironment = definition.Environments.FirstOrDefault(e => e.Name == environmentName);
                    if (definitionEnvironment == null)
                    {
                        continue;
                    }

                    Release[] definitionReleases = releases
                                                   .Where(r => r.ReleaseDefinitionReference.Id == definition.Id && r.Environments.Any(e => e.Name == environmentName))
                                                   .OrderBy(r => r.CreatedOn)
                                                   .ToArray();

                    Release lastSuccess = definitionReleases.LastOrDefault(r => r.Environments.First(e => e.Name == environmentName).Status == EnvironmentStatus.Succeeded);
                    Release last        = definitionReleases.LastOrDefault();

                    ReleaseEnvironment releaseEnvironment = last?.Environments.First(e => e.Name == environmentName);

                    environment.Releases.Add(new DisplayRelease
                    {
                        Id                      = last?.Id ?? 0,
                        DefinitionId            = definition.Id,
                        EnvironmentId           = releaseEnvironment?.Id,
                        Name                    = definition.Name,
                        AvailableVersion        = last != null ? Regex.Match(last.Name, Settings.GlobalSettings.Current.ReleaseNameExtractVersionRegex).Value : null,
                        AvailableVersionLink    = (last?.Links.Links["web"] as ReferenceLink)?.Href,
                        LastDeployedVersion     = lastSuccess != null ? Regex.Match(lastSuccess.Name, Settings.GlobalSettings.Current.ReleaseNameExtractVersionRegex).Value : String.Empty,
                        LastDeployedVersionLink = (lastSuccess?.Links.Links["web"] as ReferenceLink)?.Href,
                        Status                  = (DisplayReleaseStatus?)releaseEnvironment?.Status
                    });
                }

                environments.Add(environment);
            }

            return(environments);
        }