forked from psake/psake-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myget.psm1
44 lines (38 loc) · 1.42 KB
/
myget.psm1
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
function MyGet-SetBuildNumber([string]$buildNumber) {
MyGet-WriteServiceMessage 'buildNumber' $buildNumber
}
function MyGet-WriteBuildLogMessage([string]$text, [string]$errorDetails, [string]$status) {
MyGet-WriteServiceMessage 'message ' @{ text=$text; errorDetails=$errorDetails; status=$status}
}
function MyGet-SetEnvironmentVariable([string]$name, [string]$value) {
MyGet-WriteServiceMessage 'setParameter' @{ name=$name; value=$value}
}
function MyGet-ReportBuildProblem([string]$buildProblem) {
MyGet-WriteServiceMessage 'buildProblem' @{ description=$buildProblem; }
}
function MyGet-WriteServiceMessage([string]$messageName, $messageAttributesHashOrSingleValue) {
function escape([string]$value) {
([char[]] $value |
%{ switch ($_)
{
"|" { "||" }
"'" { "|'" }
"`n" { "|n" }
"`r" { "|r" }
"[" { "|[" }
"]" { "|]" }
([char] 0x0085) { "|x" }
([char] 0x2028) { "|l" }
([char] 0x2029) { "|p" }
default { $_ }
}
} ) -join ''
}
if ($messageAttributesHashOrSingleValue -is [hashtable]) {
$messageAttributesString = ($messageAttributesHashOrSingleValue.GetEnumerator() |
%{ "{0}='{1}'" -f $_.Key, (escape $_.Value) }) -join ' '
} else {
$messageAttributesString = ("'{0}'" -f (escape $messageAttributesHashOrSingleValue))
}
Write-Output "##myget[$messageName $messageAttributesString]"
}