Skip to content

Commit

Permalink
Merge pull request #308 from yansklyarenko/feature/GH-222-add-overloa…
Browse files Browse the repository at this point in the history
…d-which-does-not-throw
  • Loading branch information
pascalberger committed Oct 16, 2021
2 parents 13df2bd + 44ff0aa commit a450f05
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs
Expand Up @@ -89,6 +89,42 @@ public static partial class AzureDevOpsAliases
return AzureDevOpsBuild(context, settings);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
/// should be thrown if build could not be found.</param>
/// <example>
/// <para>Get current Azure Pipelines build. Don't throw exception in case the build is not found:</para>
/// <code>
/// <![CDATA[
/// var build =
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(false);
/// ]]>
/// </code>
/// </example>
/// <returns>Description of the build.
/// Returns <c>null</c> if build could not be found and
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
[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);
}

/// <summary>
/// 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.
Expand All @@ -100,7 +136,7 @@ public static partial class AzureDevOpsAliases
/// <code>
/// <![CDATA[
/// var build =
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken();
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42);
/// ]]>
/// </code>
/// </example>
Expand All @@ -124,6 +160,45 @@ public static partial class AzureDevOpsAliases
return AzureDevOpsBuild(context, settings);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="buildId">ID of the build.</param>
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
/// should be thrown if build could not be found.</param>
/// <example>
/// <para>Get an Azure Pipelines build. Don't throw exception in case the build is not found:</para>
/// <code>
/// <![CDATA[
/// var build =
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42, false);
/// ]]>
/// </code>
/// </example>
/// <returns>Description of the build.
/// Returns <c>null</c> if build could not be found and
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
[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);
}

/// <summary>
/// Gets Azure Pipelines builds using the specified settings.
/// </summary>
Expand Down

0 comments on commit a450f05

Please sign in to comment.