forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Add-ADOAttachment.ps1
91 lines (81 loc) · 3.66 KB
/
Add-ADOAttachment.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function Add-ADOAttachment
{
<#
.Synopsis
Adds an ADO Attachment
.Description
Adds an Azure DevOps Attachment
.Example
Add-ADOAttachment -Path .\a.zip
.Example
Add-ADOAttachment -Path .\summary.md -IsSummary
.Example
Add-ADOAttachment -Path .\log.txt -IsLog
.Link
https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands
#>
[CmdletBinding(DefaultParameterSetName='task.uploadfile')]
[OutputType([string])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification="Directly outputs in certain scenarios")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Test-ForUnusableFunction", "", Justification="Directly outputs in certain scenarios")]
param(
# The attachment path.
[Parameter(Mandatory,ParameterSetName='task.uploadfile',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='task.addattachment',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='task.uploadsummary',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='task.uploadlog',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='artifact.upload',ValueFromPipelineByPropertyName)]
[Alias('Fullname')]
[string]
$Path,
# The Attachment name. This is used to upload information for an Azure DevOps extension.
[Parameter(Mandatory,Position=0,ParameterSetName='task.addattachment',ValueFromPipelineByPropertyName)]
[string]
$Name,
# The Attachment type. This is used to upload information for an Azure DevOps extension.
[Parameter(Mandatory,Position=1,ParameterSetName='task.addattachment',ValueFromPipelineByPropertyName)]
[string]
$Type,
# The Container Folder. This is required when uploading artifacts.
[Parameter(Mandatory,ParameterSetName='artifact.upload',ValueFromPipelineByPropertyName)]
[string]
$ContainerFolder,
# The Artifact Name.
[Parameter(Mandatory,ParameterSetName='artifact.upload',ValueFromPipelineByPropertyName)]
[string]
$ArtifactName,
# If set, the upload will be treated as a summary. Summary uploads must be markdown.
[Parameter(Mandatory,ParameterSetName='task.uploadsummary',ValueFromPipelineByPropertyName)]
[Alias('Summary')]
[switch]
$IsSummary,
# If set, the upload will be treated as a log file.
[Parameter(Mandatory,ParameterSetName='task.uploadlog',ValueFromPipelineByPropertyName)]
[Alias('Log')]
[switch]
$IsLog)
begin {
$cmdMd = [Management.Automation.CommandMetaData]$MyInvocation.MyCommand
}
process {
if ($DebugPreference -eq 'SilentlyContinue') {
$rp = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($Path)
if (-not $rp) { return }
} else {
$rp = $Path
}
$properties = # Collect the optional properties
@(foreach ($kv in $PSBoundParameters.GetEnumerator()) {
if ($kv.Key -eq 'Path') { continue } # (anything parameter but Path
if ($kv.Value -is [switch]) {continue } # that is not a switch parameter).
if (-not $cmdMd.Parameters.ContainsKey($kv.Key)) { continue }
"$($kv.Key.ToLower())=$($kv.Value)"
}) -join ';'
$out = "##vso[$($pscmdlet.ParameterSetName)$(if ($properties) {" $properties"})]$rp"
if ($env:AGENT_ID -and $DebugPreference -eq 'SilentlyContinue') {
Write-Host $out
} else {
$out
}
}
}