Skip to content

Commit a450f05

Browse files
authored
Merge pull request #308 from yansklyarenko/feature/GH-222-add-overload-which-does-not-throw
2 parents 13df2bd + 44ff0aa commit a450f05

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
8989
return AzureDevOpsBuild(context, settings);
9090
}
9191

92+
/// <summary>
93+
/// Gets the description of the Azure Pipelines build which is running.
94+
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
95+
/// </summary>
96+
/// <param name="context">The context.</param>
97+
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
98+
/// should be thrown if build could not be found.</param>
99+
/// <example>
100+
/// <para>Get current Azure Pipelines build. Don't throw exception in case the build is not found:</para>
101+
/// <code>
102+
/// <![CDATA[
103+
/// var build =
104+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(false);
105+
/// ]]>
106+
/// </code>
107+
/// </example>
108+
/// <returns>Description of the build.
109+
/// Returns <c>null</c> if build could not be found and
110+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
111+
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
112+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
113+
[CakeMethodAlias]
114+
[CakeAliasCategory("Azure Pipelines")]
115+
[CakeNamespaceImport("Cake.AzureDevOps.Pipelines")]
116+
public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
117+
this ICakeContext context,
118+
bool throwExceptionIfBuildCouldNotBeFound)
119+
{
120+
context.NotNull(nameof(context));
121+
122+
var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken();
123+
settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound;
124+
125+
return AzureDevOpsBuild(context, settings);
126+
}
127+
92128
/// <summary>
93129
/// Gets the description of a specific build which is running the access token provided by Azure Pipelines.
94130
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
@@ -100,7 +136,7 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
100136
/// <code>
101137
/// <![CDATA[
102138
/// var build =
103-
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken();
139+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42);
104140
/// ]]>
105141
/// </code>
106142
/// </example>
@@ -124,6 +160,45 @@ public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
124160
return AzureDevOpsBuild(context, settings);
125161
}
126162

163+
/// <summary>
164+
/// Gets the description of a specific build which is running the access token provided by Azure Pipelines.
165+
/// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
166+
/// </summary>
167+
/// <param name="context">The context.</param>
168+
/// <param name="buildId">ID of the build.</param>
169+
/// <param name="throwExceptionIfBuildCouldNotBeFound">Value indicating whether an exception
170+
/// should be thrown if build could not be found.</param>
171+
/// <example>
172+
/// <para>Get an Azure Pipelines build. Don't throw exception in case the build is not found:</para>
173+
/// <code>
174+
/// <![CDATA[
175+
/// var build =
176+
/// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42, false);
177+
/// ]]>
178+
/// </code>
179+
/// </example>
180+
/// <returns>Description of the build.
181+
/// Returns <c>null</c> if build could not be found and
182+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
183+
/// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
184+
/// <paramref name="throwExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
185+
[CakeMethodAlias]
186+
[CakeAliasCategory("Azure Pipelines")]
187+
[CakeNamespaceImport("Cake.AzureDevOps.Pipelines")]
188+
public static AzureDevOpsBuild AzureDevOpsBuildUsingAzurePipelinesOAuthToken(
189+
this ICakeContext context,
190+
int buildId,
191+
bool throwExceptionIfBuildCouldNotBeFound)
192+
{
193+
context.NotNull(nameof(context));
194+
buildId.NotNegativeOrZero(nameof(buildId));
195+
196+
var settings = AzureDevOpsBuildSettings.UsingAzurePipelinesOAuthToken(buildId);
197+
settings.ThrowExceptionIfBuildCouldNotBeFound = throwExceptionIfBuildCouldNotBeFound;
198+
199+
return AzureDevOpsBuild(context, settings);
200+
}
201+
127202
/// <summary>
128203
/// Gets Azure Pipelines builds using the specified settings.
129204
/// </summary>

0 commit comments

Comments
 (0)