Ejemplo n.º 1
0
        static void RunOptions(Options opts)
        {
            VssCredentials creds = new VssBasicCredential(string.Empty, personalAccessToken);

            // Connect to Azure DevOps Services
            VssConnection connection = new VssConnection(new Uri(collectionUri), creds);

            // Get a Release EndPoint
            ReleaseHttpClient releaseHttpClient = connection.GetClient <ReleaseHttpClient>();

            // Get data about a specific repository
            ReleaseDefinition definition = releaseHttpClient.GetReleaseDefinitionAsync(opts.ProjectName, opts.ReleaseId).Result;

            List <ReleaseDefinitionEnvironment> environments = definition.Environments as List <ReleaseDefinitionEnvironment>;

            environments.Sort();


            foreach (var env in environments)
            {
                Console.WriteLine();
                Console.WriteLine($"## {env.Name}");
                Console.WriteLine();

                foreach (var variable in env.Variables)
                {
                    Console.WriteLine($"{variable.Key}#{variable.Value.Value}");
                }
            }
        }
Ejemplo n.º 2
0
        public ReleaseDefinition GetReleaseDefinition()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

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

            // Show a release definitions
            ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result;

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

            return(releaseDefinition);
        }
Ejemplo n.º 3
0
        public ReleaseDefinition GetReleaseDefinition(int id, string accessToken)
        {
            if (id < 0)
            {
                throw new ArgumentException("id cannot be less than 0", nameof(id));
            }
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentException("parameter cannot be null or whitespace", nameof(accessToken));
            }

            this.logger.LogDebug($"getting release definition. id:[{id}]");

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

            return(client.GetReleaseDefinitionAsync(this.vstsConfig.ProjectName, id).Result);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public ReleaseDefinition UpdateReleaseDefinition()
        {
            string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;

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

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

            // add a non secret variable to definition
            ConfigurationVariableValue variable = new ConfigurationVariableValue();

            variable.Value    = "NonSecretValue";
            variable.IsSecret = false;
            releaseDefinition.Variables.Add("NonSecretVariable", variable);

            // update release definition
            ReleaseDefinition updatedReleaseDefinition = releaseClient.UpdateReleaseDefinitionAsync(project: projectName, releaseDefinition: releaseDefinition).Result;

            Console.WriteLine("{0} {1} {2}", updatedReleaseDefinition.Id.ToString().PadLeft(6), updatedReleaseDefinition.Revision, updatedReleaseDefinition.ModifiedOn);

            return(releaseDefinition);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            VssCredentials creds = new VssBasicCredential(string.Empty, personalAccessToken);

            // Connect to Azure DevOps Services
            VssConnection connection = new VssConnection(new Uri(collectionUri), creds);

            // Get a Release EndPoint
            ReleaseHttpClient releaseHttpClient = connection.GetClient <ReleaseHttpClient>();


            // Get data about a specific repository
            ReleaseDefinition definition = releaseHttpClient.GetReleaseDefinitionAsync(projectName, releaseDefinitionId).Result;


            //Determine if it is a release or a stage variable
            int environmentIndex = GetEnvironmentIndex(environmentName, definition.Environments);

            // Read Tokens from file (non secret variables)
            // Format per line : key#value
            var tokens = ReadTokensFromFile(tokenFilename);

            if (environmentIndex == -1)
            {
                foreach (var t in tokens)
                {
                    if (!definition.Variables.ContainsKey(t.Name))
                    {
                        definition.Variables.Add(t.Name, new ConfigurationVariableValue {
                            Value = t.Value, IsSecret = false
                        });
                    }
                    else
                    {
                        definition.Variables[t.Name] = new ConfigurationVariableValue {
                            Value = t.Value, IsSecret = false
                        }
                    };
                }
            }
            else
            {
                foreach (var t in tokens)
                {
                    if (!definition.Environments[environmentIndex].Variables.ContainsKey(t.Name))
                    {
                        definition.Environments[environmentIndex].Variables.Add(t.Name, new ConfigurationVariableValue {
                            Value = t.Value, IsSecret = false
                        });
                    }
                    else
                    {
                        definition.Environments[environmentIndex].Variables[t.Name] = new ConfigurationVariableValue {
                            Value = t.Value, IsSecret = false
                        }
                    };
                }
            }


            // Update Release Definition
            ReleaseDefinition updatedDefinition = releaseHttpClient.UpdateReleaseDefinitionAsync(definition, projectName).Result;
        }
Ejemplo n.º 7
0
 static ReleaseDefinition GetReleaseDefintion(ReleaseHttpClient rmClient, int releaseDefintionId)
 {
     return(rmClient.GetReleaseDefinitionAsync(projectName, releaseDefintionId).Result);
 }