/// <summary>
        /// Initializes a new instance of the <see cref="AzureDevOpsBuildSettings"/> class using environment variables
        /// as set by an Azure Pipelines build.
        /// </summary>
        /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param>
        public AzureDevOpsBuildSettings(IAzureDevOpsCredentials credentials)
        {
            credentials.NotNull(nameof(credentials));

            this.Credentials   = credentials;
            this.CollectionUrl = EnvironmentVariableHelper.GetSystemTeamFoundationCollectionUri();
            this.ProjectName   = EnvironmentVariableHelper.GetSystemTeamProject();

            var buildId = Environment.GetEnvironmentVariable("BUILD_BUILDID", EnvironmentVariableTarget.Process);

            if (string.IsNullOrWhiteSpace(buildId))
            {
                throw new InvalidOperationException(
                          "Failed to read the BUILD_BUILDID environment variable. Make sure you are running in an Azure Pipelines build.");
            }

            if (!int.TryParse(buildId, out int buildIdValue))
            {
                throw new InvalidOperationException("BUILD_BUILDID environment variable should contain integer value");
            }

            if (buildIdValue <= 0)
            {
                throw new InvalidOperationException("BUILD_BUILDID environment variable should contain integer value and it should be greater than zero");
            }

            this.BuildId = buildIdValue;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureDevOpsBuildsSettings"/> class using environment variables
        /// as set by an Azure Pipelines build.
        /// </summary>
        /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param>
        public AzureDevOpsBuildsSettings(IAzureDevOpsCredentials credentials)
        {
            credentials.NotNull(nameof(credentials));

            this.Credentials   = credentials;
            this.CollectionUrl = EnvironmentVariableHelper.GetSystemTeamFoundationCollectionUri();
            this.ProjectName   = EnvironmentVariableHelper.GetSystemTeamProject();
        }