Exemple #1
0
        public override async Task <IEnumerable <string> > EnumerateValuesAsync(ValueEnumerationContext context)
        {
            var credentials = ResourceCredentials.Create <TfsCredentials>(this.CredentialName);

            var api         = new TfsRestApi(credentials, null);
            var definitions = await api.GetBuildDefinitionsAsync(this.TeamProjectName).ConfigureAwait(false);

            return(definitions.Select(d => d.name));
        }
Exemple #2
0
        public async override Task ExecuteAsync(IOperationExecutionContext context)
        {
            var api = new TfsRestApi(this, this);

            this.LogDebug("Finding VSO build definition...");
            var definitionResult = await api.GetBuildDefinitionsAsync(this.TeamProject);

            var definition = definitionResult.FirstOrDefault(d => string.IsNullOrEmpty(this.BuildDefinition) || string.Equals(d.name, this.BuildDefinition, StringComparison.OrdinalIgnoreCase));

            if (definition == null)
            {
                throw new InvalidOperationException("Could not find a build definition named: " + AH.CoalesceString(this.BuildDefinition, "any"));
            }

            this.LogInformation($"Queueing VSO build of {this.TeamProject}, build definition {definition.name}...");

            var queuedBuild = await api.QueueBuildAsync(this.TeamProject, definition.id);

            this.LogInformation($"Build number \"{queuedBuild.buildNumber}\" created for definition \"{queuedBuild.definition.name}\".");

            this.TfsBuildNumber = queuedBuild.buildNumber;

            if (this.WaitForCompletion)
            {
                string lastStatus = queuedBuild.status;
                this.LogInformation($"Current build status is \"{lastStatus}\", waiting for \"completed\" status...");

                while (!string.Equals(queuedBuild.status, "completed", StringComparison.OrdinalIgnoreCase))
                {
                    await Task.Delay(4000, context.CancellationToken);

                    queuedBuild = await api.GetBuildAsync(this.TeamProject, queuedBuild.id);

                    if (queuedBuild.status != lastStatus)
                    {
                        this.LogInformation($"Current build status changed from \"{lastStatus}\" to \"{queuedBuild.status}\"...");
                        lastStatus = queuedBuild.status;
                    }
                }

                this.LogInformation("Build status result is \"completed\".");

                if (this.ValidateBuild)
                {
                    this.LogInformation("Validating build status result is \"succeeded\"...");
                    if (!string.Equals("succeeded", queuedBuild.result, StringComparison.OrdinalIgnoreCase))
                    {
                        this.LogError("Build status result was not \"succeeded\".");
                        return;
                    }
                    this.LogInformation("Build status result was \"succeeded\".");
                }
            }

            this.LogInformation($"VSO build {queuedBuild.buildNumber} created.");
        }
        public async Task <IEnumerable <string> > GetSuggestionsAsync(IComponentConfiguration config)
        {
            var credentialName = config["CredentialName"];
            var projectName    = AH.CoalesceString(config["TeamProject"], config["TeamProjectName"]);

            if (string.IsNullOrEmpty(credentialName) || string.IsNullOrEmpty(projectName))
            {
                return(Enumerable.Empty <string>());
            }

            var credentials = ResourceCredentials.Create <TfsCredentials>(credentialName);

            var api         = new TfsRestApi(credentials, null);
            var definitions = await api.GetBuildDefinitionsAsync(projectName).ConfigureAwait(false);

            return(definitions.Select(d => d.name));
        }