File tree Expand file tree Collapse file tree 5 files changed +142
-0
lines changed
src/Cake.AzureDevOps/Pipelines Expand file tree Collapse file tree 5 files changed +142
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace Cake . AzureDevOps . Pipelines
2
+ {
3
+ using Microsoft . TeamFoundation . Build . WebApi ;
4
+
5
+ /// <summary>
6
+ /// Extensions for the <see cref="ArtifactResource"/> class.
7
+ /// </summary>
8
+ internal static class ArtifactResourceExtensions
9
+ {
10
+ /// <summary>
11
+ /// Converts a <see cref="ArtifactResource"/> to an <see cref="AzureDevOpsBuildArtifact"/>.
12
+ /// </summary>
13
+ /// <param name="artifactResource">Artifact resource record to convert.</param>
14
+ /// <returns>Converted artifact resorce record.</returns>
15
+ public static AzureDevOpsArtifactResource ToAzureDevOpsArtifactResource ( this ArtifactResource artifactResource )
16
+ {
17
+ artifactResource . NotNull ( nameof ( artifactResource ) ) ;
18
+
19
+ return
20
+ new AzureDevOpsArtifactResource
21
+ {
22
+ Data = artifactResource . Data ,
23
+ DownloadUrl = artifactResource . DownloadUrl ,
24
+ Type = artifactResource . Type ,
25
+ Url = artifactResource . Url ,
26
+ Properties = artifactResource . Properties ,
27
+ } ;
28
+ }
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+
3
+ namespace Cake . AzureDevOps . Pipelines
4
+ {
5
+ /// <summary>
6
+ /// Represents a resource associated with a <see cref="AzureDevOpsBuildArtifact" />.
7
+ /// </summary>
8
+ public class AzureDevOpsArtifactResource
9
+ {
10
+ /// <summary>
11
+ /// Gets the data of the resource.
12
+ /// </summary>
13
+ public string Data { get ; internal set ; }
14
+
15
+ /// <summary>
16
+ /// Gets the download url of the resource.
17
+ /// </summary>
18
+ public string DownloadUrl { get ; internal set ; }
19
+
20
+ /// <summary>
21
+ /// Gets the type of the resource.
22
+ /// </summary>
23
+ public string Type { get ; internal set ; }
24
+
25
+ /// <summary>
26
+ /// Gets the full http link to the resource.
27
+ /// </summary>
28
+ public string Url { get ; internal set ; }
29
+
30
+ /// <summary>
31
+ /// Gets the properties for the resource.
32
+ /// </summary>
33
+ public Dictionary < string , string > Properties { get ; internal set ; }
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -356,6 +356,32 @@ public IEnumerable<AzureDevOpsTimelineRecord> GetTimelineRecords()
356
356
}
357
357
}
358
358
359
+ /// <summary>
360
+ /// Gets the artifacts associated with a build.
361
+ /// </summary>
362
+ /// <returns>The artifacts associated with a build or an empty list if no build could be found and
363
+ /// <see cref="AzureDevOpsBuildSettings.ThrowExceptionIfBuildCouldNotBeFound"/> is set to <c>false</c>.</returns>
364
+ /// <exception cref="AzureDevOpsBuildNotFoundException">If build could not be found and
365
+ /// <see cref="AzureDevOpsBuildSettings.ThrowExceptionIfBuildCouldNotBeFound"/> is set to <c>true</c>.</exception>
366
+ public IEnumerable < AzureDevOpsBuildArtifact > GetArtifacts ( )
367
+ {
368
+ if ( ! this . ValidateBuild ( ) )
369
+ {
370
+ return new List < AzureDevOpsBuildArtifact > ( ) ;
371
+ }
372
+
373
+ using ( var buildClient = this . buildClientFactory . CreateBuildClient ( this . CollectionUrl , this . credentials ) )
374
+ {
375
+ return
376
+ buildClient
377
+ . GetArtifactsAsync ( this . ProjectId , this . BuildId )
378
+ . ConfigureAwait ( false )
379
+ . GetAwaiter ( )
380
+ . GetResult ( )
381
+ . Select ( x => x . ToAzureDevOpsBuildArtifact ( ) ) ;
382
+ }
383
+ }
384
+
359
385
/// <summary>
360
386
/// Validates if a build could be found.
361
387
/// Depending on <see cref="AzureDevOpsBuildSettings.ThrowExceptionIfBuildCouldNotBeFound"/>
Original file line number Diff line number Diff line change
1
+ namespace Cake . AzureDevOps . Pipelines
2
+ {
3
+ /// <summary>
4
+ /// Represents an artifact associated with a build.
5
+ /// </summary>
6
+ public class AzureDevOpsBuildArtifact
7
+ {
8
+ /// <summary>
9
+ /// Gets the id of the artifact.
10
+ /// </summary>
11
+ public int Id { get ; internal set ; }
12
+
13
+ /// <summary>
14
+ /// Gets the name of the artifact.
15
+ /// </summary>
16
+ public string Name { get ; internal set ; }
17
+
18
+ /// <summary>
19
+ /// Gets the artifact resource.
20
+ /// </summary>
21
+ public AzureDevOpsArtifactResource Resource { get ; internal set ; }
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ namespace Cake . AzureDevOps . Pipelines
2
+ {
3
+ using Microsoft . TeamFoundation . Build . WebApi ;
4
+
5
+ /// <summary>
6
+ /// Extensions for the <see cref="BuildArtifact"/> class.
7
+ /// </summary>
8
+ internal static class BuildArtifactExtensions
9
+ {
10
+ /// <summary>
11
+ /// Converts a <see cref="BuildArtifact"/> to an <see cref="AzureDevOpsBuildArtifact"/>.
12
+ /// </summary>
13
+ /// <param name="buildArtifact">Build artifact record to convert.</param>
14
+ /// <returns>Converted build artifact record.</returns>
15
+ public static AzureDevOpsBuildArtifact ToAzureDevOpsBuildArtifact ( this BuildArtifact buildArtifact )
16
+ {
17
+ buildArtifact . NotNull ( nameof ( buildArtifact ) ) ;
18
+
19
+ return
20
+ new AzureDevOpsBuildArtifact
21
+ {
22
+ Id = buildArtifact . Id ,
23
+ Name = buildArtifact . Name ,
24
+ Resource = buildArtifact . Resource . ToAzureDevOpsArtifactResource ( ) ,
25
+ } ;
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments