From 44ff0aa638ff30f57b9544227ca9af5915d29ae1 Mon Sep 17 00:00:00 2001 From: Yan Sklyarenko Date: Sat, 16 Oct 2021 22:23:57 +0300 Subject: [PATCH] (GH-222) Add overload which does not throw Add overload for AzureDevOpsBuildUsingAzurePipelinesOAuthToken which does not throw --- .../AzureDevOpsAliases.Pipelines.cs | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs b/src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs index b5f9257e..20769ac6 100644 --- a/src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs +++ b/src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs @@ -89,6 +89,42 @@ public static partial class AzureDevOpsAliases return AzureDevOpsBuild(context, settings); } + /// + /// Gets the description of the Azure Pipelines build which is running. + /// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled. + /// + /// The context. + /// Value indicating whether an exception + /// should be thrown if build could not be found. + /// + /// Get current Azure Pipelines build. Don't throw exception in case the build is not found: + /// + /// + /// + /// + /// Description of the build. + /// Returns null if build could not be found and + /// is set to false. + /// If build could not be found and + /// is set to true. + [CakeMethodAlias] + [CakeAliasCategory("Azure Pipelines")] + [CakeNamespaceImport("Cake.AzureDevOps.Pipelines")] + public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken( + this ICakeContext context, + bool throwExceptionIfBuildCouldNotBeFound) + { + context.NotNull(nameof(context)); + + var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken(); + settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound; + + return AzureDevOpsBuild(context, settings); + } + /// /// Gets the description of a specific build which is running the access token provided by Azure Pipelines. /// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled. @@ -100,7 +136,7 @@ public static partial class AzureDevOpsAliases /// /// /// /// @@ -124,6 +160,45 @@ public static partial class AzureDevOpsAliases return AzureDevOpsBuild(context, settings); } + /// + /// Gets the description of a specific build which is running the access token provided by Azure Pipelines. + /// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled. + /// + /// The context. + /// ID of the build. + /// Value indicating whether an exception + /// should be thrown if build could not be found. + /// + /// Get an Azure Pipelines build. Don't throw exception in case the build is not found: + /// + /// + /// + /// + /// Description of the build. + /// Returns null if build could not be found and + /// is set to false. + /// If build could not be found and + /// is set to true. + [CakeMethodAlias] + [CakeAliasCategory("Azure Pipelines")] + [CakeNamespaceImport("Cake.AzureDevOps.Pipelines")] + public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken( + this ICakeContext context, + int buildId, + bool throwExceptionIfBuildCouldNotBeFound) + { + context.NotNull(nameof(context)); + buildId.NotNegativeOrZero(nameof(buildId)); + + var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken(buildId); + settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound; + + return AzureDevOpsBuild(context, settings); + } + /// /// Gets Azure Pipelines builds using the specified settings. ///