@@ -92,6 +92,68 @@ function Exec-Process([string]$command, [string]$commandArgs) {
92
92
}
93
93
}
94
94
95
+ function Write-PipelineTaskError {
96
+ [CmdletBinding ()]
97
+ param (
98
+ [Parameter (Mandatory = $true )]
99
+ [string ]$Message ,
100
+ [Parameter (Mandatory = $false )]
101
+ [string ]$Type = ' error' ,
102
+ [string ]$ErrCode ,
103
+ [string ]$SourcePath ,
104
+ [string ]$LineNumber ,
105
+ [string ]$ColumnNumber ,
106
+ [switch ]$AsOutput )
107
+
108
+ if (! $ci ) {
109
+ if ($Type -eq ' error' ) {
110
+ Write-Error $Message
111
+ return
112
+ }
113
+ elseif ($Type -eq ' warning' ) {
114
+ Write-Warning $Message
115
+ return
116
+ }
117
+ }
118
+
119
+ if (($Type -ne ' error' ) -and ($Type -ne ' warning' )) {
120
+ Write-Host $Message
121
+ return
122
+ }
123
+ if (-not $PSBoundParameters.ContainsKey (' Type' )) {
124
+ $PSBoundParameters.Add (' Type' , ' error' )
125
+ }
126
+ Write-LogIssue @PSBoundParameters
127
+ }
128
+
129
+ function Write-PipelineSetVariable {
130
+ [CmdletBinding ()]
131
+ param (
132
+ [Parameter (Mandatory = $true )]
133
+ [string ]$Name ,
134
+ [string ]$Value ,
135
+ [switch ]$Secret ,
136
+ [switch ]$AsOutput )
137
+
138
+ if ($ci ) {
139
+ Write-LoggingCommand - Area ' task' - Event ' setvariable' - Data $Value - Properties @ {
140
+ ' variable' = $Name
141
+ ' issecret' = $Secret
142
+ } - AsOutput:$AsOutput
143
+ }
144
+ }
145
+
146
+ function Write-PipelinePrependPath {
147
+ [CmdletBinding ()]
148
+ param (
149
+ [Parameter (Mandatory = $true )]
150
+ [string ]$Path ,
151
+ [switch ]$AsOutput )
152
+ if ($ci ) {
153
+ Write-LoggingCommand - Area ' task' - Event ' prependpath' - Data $Path - AsOutput:$AsOutput
154
+ }
155
+ }
156
+
95
157
function InitializeDotNetCli ([bool ]$install ) {
96
158
if (Test-Path variable:global:_DotNetInstallDir) {
97
159
return $global :_DotNetInstallDir
@@ -134,7 +196,7 @@ function InitializeDotNetCli([bool]$install) {
134
196
if ($install ) {
135
197
InstallDotNetSdk $dotnetRoot $dotnetSdkVersion
136
198
} else {
137
- Write-Host " Unable to find dotnet with SDK version '$dotnetSdkVersion '" - ForegroundColor Red
199
+ Write-PipelineTaskError " Unable to find dotnet with SDK version '$dotnetSdkVersion '"
138
200
ExitWithExitCode 1
139
201
}
140
202
}
@@ -147,12 +209,10 @@ function InitializeDotNetCli([bool]$install) {
147
209
# It also ensures that VS msbuild will use the downloaded sdk targets.
148
210
$env: PATH = " $dotnetRoot ;$env: PATH "
149
211
150
- if ($ci ) {
151
- # Make Sure that our bootstrapped dotnet cli is avaliable in future steps of the Azure Pipelines build
152
- Write-Host " ##vso[task.prependpath]$dotnetRoot "
153
- Write-Host " ##vso[task.setvariable variable=DOTNET_MULTILEVEL_LOOKUP]0"
154
- Write-Host " ##vso[task.setvariable variable=DOTNET_SKIP_FIRST_TIME_EXPERIENCE]1"
155
- }
212
+ # Make Sure that our bootstrapped dotnet cli is avaliable in future steps of the Azure Pipelines build
213
+ Write-PipelinePrependPath - Path $dotnetRoot
214
+ Write-PipelineSetVariable - Name ' DOTNET_MULTILEVEL_LOOKUP' - Value ' 0'
215
+ Write-PipelineSetVariable - Name ' DOTNET_SKIP_FIRST_TIME_EXPERIENCE' - Value ' 1'
156
216
157
217
return $global :_DotNetInstallDir = $dotnetRoot
158
218
}
@@ -184,7 +244,7 @@ function InstallDotNet([string] $dotnetRoot, [string] $version, [string] $archit
184
244
185
245
& $installScript @installParameters
186
246
if ($lastExitCode -ne 0 ) {
187
- Write-Host " Failed to install dotnet cli (exit code '$lastExitCode ')." - ForegroundColor Red
247
+ Write-PipelineTaskError - Message " Failed to install dotnet cli (exit code '$lastExitCode ')."
188
248
ExitWithExitCode $lastExitCode
189
249
}
190
250
}
@@ -358,7 +418,7 @@ function InitializeBuildTool() {
358
418
359
419
if ($msbuildEngine -eq " dotnet" ) {
360
420
if (! $dotnetRoot ) {
361
- Write-Host " /global.json must specify 'tools.dotnet'." - ForegroundColor Red
421
+ Write-PipelineTaskError " /global.json must specify 'tools.dotnet'."
362
422
ExitWithExitCode 1
363
423
}
364
424
@@ -367,13 +427,13 @@ function InitializeBuildTool() {
367
427
try {
368
428
$msbuildPath = InitializeVisualStudioMSBuild - install:$restore
369
429
} catch {
370
- Write-Host $_ - ForegroundColor Red
430
+ Write-PipelineTaskError $_
371
431
ExitWithExitCode 1
372
432
}
373
433
374
434
$buildTool = @ { Path = $msbuildPath ; Command = " " ; Tool = " vs" ; Framework = " net472" }
375
435
} else {
376
- Write-Host " Unexpected value of -msbuildEngine: '$msbuildEngine '." - ForegroundColor Red
436
+ Write-PipelineTaskError " Unexpected value of -msbuildEngine: '$msbuildEngine '."
377
437
ExitWithExitCode 1
378
438
}
379
439
@@ -390,7 +450,7 @@ function GetDefaultMSBuildEngine() {
390
450
return " dotnet"
391
451
}
392
452
393
- Write-Host " -msbuildEngine must be specified, or /global.json must specify 'tools.dotnet' or 'tools.vs'." - ForegroundColor Red
453
+ Write-PipelineTaskError " -msbuildEngine must be specified, or /global.json must specify 'tools.dotnet' or 'tools.vs'."
394
454
ExitWithExitCode 1
395
455
}
396
456
@@ -441,7 +501,7 @@ function InitializeToolset() {
441
501
}
442
502
443
503
if (-not $restore ) {
444
- Write-Host " Toolset version $toolsetVersion has not been restored." - ForegroundColor Red
504
+ Write-PipelineTaskError " Toolset version $toolsetVersion has not been restored."
445
505
ExitWithExitCode 1
446
506
}
447
507
@@ -526,7 +586,7 @@ function MSBuild-Core() {
526
586
$exitCode = Exec- Process $buildTool.Path $cmdArgs
527
587
528
588
if ($exitCode -ne 0 ) {
529
- Write-Host " Build failed." - ForegroundColor Red
589
+ Write-PipelineTaskError " Build failed."
530
590
531
591
$buildLog = GetMSBuildBinaryLogCommandLineArgument $args
532
592
if ($buildLog -ne $null ) {
@@ -554,6 +614,8 @@ function GetMSBuildBinaryLogCommandLineArgument($arguments) {
554
614
return $null
555
615
}
556
616
617
+ . $PSScriptRoot \LoggingCommandFunctions.ps1
618
+
557
619
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot " ..\.." )
558
620
$EngRoot = Resolve-Path (Join-Path $PSScriptRoot " .." )
559
621
$ArtifactsDir = Join-Path $RepoRoot " artifacts"
@@ -569,11 +631,8 @@ Create-Directory $ToolsetDir
569
631
Create- Directory $TempDir
570
632
Create- Directory $LogDir
571
633
572
- if ($ci ) {
573
- Write-Host " ##vso[task.setvariable variable=Artifacts]$ArtifactsDir "
574
- Write-Host " ##vso[task.setvariable variable=Artifacts.Toolset]$ToolsetDir "
575
- Write-Host " ##vso[task.setvariable variable=Artifacts.Log]$LogDir "
576
-
577
- $env: TEMP = $TempDir
578
- $env: TMP = $TempDir
579
- }
634
+ Write-PipelineSetVariable - Name ' Artifacts' - Value $ArtifactsDir
635
+ Write-PipelineSetVariable - Name ' Artifacts.Toolset' - Value $ToolsetDir
636
+ Write-PipelineSetVariable - Name ' Artifacts.Log' - Value $LogDir
637
+ Write-PipelineSetVariable - Name ' TEMP' - Value $TempDir
638
+ Write-PipelineSetVariable - Name ' TMP' - Value $TempDir
0 commit comments