/// <summary> /// Returns the <see cref="VssCredentials"/> corresponding to a <see cref="IAzureDevOpsCredentials"/> object. /// </summary> /// <param name="credentials"><see cref="IAzureDevOpsCredentials"/> credential instance.</param> /// <returns><see cref="VssCredentials"/> instance.</returns> public static VssCredentials ToVssCredentials(this IAzureDevOpsCredentials credentials) { credentials.NotNull(nameof(credentials)); switch (credentials.GetType().Name) { case nameof(AzureDevOpsNtlmCredentials): return(new VssCredentials()); case nameof(AzureDevOpsBasicCredentials): var basicCredentials = (AzureDevOpsBasicCredentials)credentials; return(new VssBasicCredential(basicCredentials.UserName, basicCredentials.Password)); case nameof(AzureDevOpsOAuthCredentials): var oAuthCredentials = (AzureDevOpsOAuthCredentials)credentials; return(new VssOAuthAccessTokenCredential(oAuthCredentials.AccessToken)); case nameof(AzureDevOpsAadCredentials): var aadCredentials = (AzureDevOpsAadCredentials)credentials; return(new VssAadCredential(aadCredentials.UserName, aadCredentials.Password)); default: throw new AzureDevOpsException("Unknown credential type."); } }
/// <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; }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="BaseAzureDevOpsPullRequestSettings"/> class. /// </summary> /// <param name="repositoryUrl">Full URL of the Git repository, /// eg. <code>http://myserver:8080/defaultcollection/myproject/_git/myrepository</code>. /// Supported URL schemes are HTTP, HTTPS and SSH. /// URLs using SSH scheme are converted to HTTPS.</param> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> protected BaseAzureDevOpsPullRequestSettings(Uri repositoryUrl, IAzureDevOpsCredentials credentials) { repositoryUrl.NotNull(nameof(repositoryUrl)); credentials.NotNull(nameof(credentials)); this.RepositoryUrl = repositoryUrl; this.Credentials = credentials; }
public static IPullRequestSystem AzureDevOpsPullRequests( this ICakeContext context, IAzureDevOpsCredentials credentials) { context.NotNull(nameof(context)); credentials.NotNull(nameof(credentials)); return(context.AzureDevOpsPullRequests(new AzureDevOpsPullRequestSystemSettings(credentials))); }
/// <summary> /// Initializes a new instance of the <see cref="AzureDevOpsBuildsSettings"/> class. /// </summary> /// <param name="collectionUrl">Full URL of the Azure DevOps collection, /// eg. <code>http://myserver:8080/defaultcollection</code>.</param> /// <param name="projectName">Name of the project.</param> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> public AzureDevOpsBuildsSettings(Uri collectionUrl, string projectName, IAzureDevOpsCredentials credentials) { collectionUrl.NotNull(nameof(collectionUrl)); projectName.NotNullOrWhiteSpace(nameof(projectName)); credentials.NotNull(nameof(credentials)); this.CollectionUrl = collectionUrl; this.ProjectName = projectName; this.Credentials = credentials; }
/// <summary> /// Initializes a new instance of the <see cref="BaseAzureDevOpsPullRequestSettings"/> class. /// </summary> /// <param name="repositoryUrl">Full URL of the Git repository, /// eg. <code>http://myserver:8080/defaultcollection/myproject/_git/myrepository</code>. /// Supported URL schemes are HTTP, HTTPS and SSH. /// URLs using SSH scheme are converted to HTTPS.</param> /// <param name="sourceRefName">Branch for which the pull request is made. /// <see cref="ArgumentException"/> if <see langword="null"/> or <see cref="string.Empty"/>.</param> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps. /// <see cref="ArgumentException"/> if <see langword="null"/>.</param> protected BaseAzureDevOpsPullRequestSettings(Uri repositoryUrl, string sourceRefName, IAzureDevOpsCredentials credentials) { repositoryUrl.NotNull(nameof(repositoryUrl)); sourceRefName.NotNullOrWhiteSpace(nameof(sourceRefName)); credentials.NotNull(nameof(credentials)); this.RepositoryUrl = repositoryUrl; this.SourceRefName = sourceRefName; this.Credentials = credentials; }
/// <summary> /// Initializes a new instance of the <see cref="AzureDevOpsBuildSettings"/> class. /// </summary> /// <param name="collectionUrl">Full URL of the Azure DevOps collection, /// eg. <code>http://myserver:8080/defaultcollection</code>.</param> /// <param name="projectName">Name of the project.</param> /// <param name="buildId">ID of the build.</param> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> public AzureDevOpsBuildSettings(Uri collectionUrl, string projectName, int buildId, IAzureDevOpsCredentials credentials) { collectionUrl.NotNull(nameof(collectionUrl)); projectName.NotNullOrWhiteSpace(nameof(projectName)); buildId.NotNegativeOrZero(nameof(buildId)); credentials.NotNull(nameof(credentials)); this.CollectionUrl = collectionUrl; this.ProjectName = projectName; this.BuildId = buildId; this.Credentials = credentials; }
public static IPullRequestSystem AzureDevOpsPullRequests( this ICakeContext context, Uri repositoryUrl, int pullRequestId, IAzureDevOpsCredentials credentials) { context.NotNull(nameof(context)); repositoryUrl.NotNull(nameof(repositoryUrl)); credentials.NotNull(nameof(credentials)); return(context.AzureDevOpsPullRequests(new AzureDevOpsPullRequestSystemSettings(repositoryUrl, pullRequestId, credentials))); }
public static IPullRequestSystem AzureDevOpsPullRequests( this ICakeContext context, Uri repositoryUrl, string sourceBranch, IAzureDevOpsCredentials credentials) { context.NotNull(nameof(context)); repositoryUrl.NotNull(nameof(repositoryUrl)); sourceBranch.NotNullOrWhiteSpace(nameof(sourceBranch)); credentials.NotNull(nameof(credentials)); return(context.AzureDevOpsPullRequests(new AzureDevOpsPullRequestSystemSettings(repositoryUrl, sourceBranch, credentials))); }
/// <summary> /// Initializes a new instance of the <see cref="AzureDevOpsBuildsSettings"/> class. /// </summary> /// <param name="collectionUrl">Full URL of the Azure DevOps collection, /// eg. <code>http://myserver:8080/defaultcollection</code>.</param> /// <param name="projectGuid">ID of the project.</param> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> public AzureDevOpsBuildsSettings(Uri collectionUrl, Guid projectGuid, IAzureDevOpsCredentials credentials) { collectionUrl.NotNull(nameof(collectionUrl)); credentials.NotNull(nameof(credentials)); if (projectGuid == Guid.Empty) { throw new ArgumentOutOfRangeException(nameof(projectGuid)); } this.Credentials = credentials; this.ProjectGuid = projectGuid; this.CollectionUrl = collectionUrl; }
/// <summary> /// Initializes a new instance of the <see cref="BaseAzureDevOpsPullRequestSettings"/> class using environment variables /// as set by an Azure Pipelines build. /// </summary> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> protected BaseAzureDevOpsPullRequestSettings(IAzureDevOpsCredentials credentials) { credentials.NotNull(nameof(credentials)); this.Credentials = credentials; var repositoryUrl = Environment.GetEnvironmentVariable("BUILD_REPOSITORY_URI", EnvironmentVariableTarget.Process); if (string.IsNullOrWhiteSpace(repositoryUrl)) { throw new InvalidOperationException( "Failed to read the BUILD_REPOSITORY_URI environment variable. Make sure you are running in an Azure Pipelines build."); } this.RepositoryUrl = new Uri(repositoryUrl); }
/// <summary> /// Initializes a new instance of the <see cref="AzureDevOpsBuildSettings"/> class using environment variables /// as set by a 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; var collectionUrl = Environment.GetEnvironmentVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", EnvironmentVariableTarget.Process); if (string.IsNullOrWhiteSpace(collectionUrl)) { throw new InvalidOperationException( "Failed to read the SYSTEM_TEAMFOUNDATIONCOLLECTIONURI environment variable. Make sure you are running in an Azure Pipelines build."); } this.CollectionUrl = new Uri(collectionUrl); var projectName = Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECT", EnvironmentVariableTarget.Process); if (string.IsNullOrWhiteSpace(projectName)) { throw new InvalidOperationException( "Failed to read the SYSTEM_TEAMPROJECT environment variable. Make sure you are running in an Azure Pipelines build."); } this.ProjectName = projectName; 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; }
/// <summary> /// Initializes a new instance of the <see cref="BaseAzureDevOpsCredentialsSettings"/> class. /// </summary> /// <param name="credentials">Credentials to use to authenticate against Azure DevOps.</param> protected BaseAzureDevOpsCredentialsSettings(IAzureDevOpsCredentials credentials) { credentials.NotNull(nameof(credentials)); this.Credentials = credentials; }