我有一个PowerShell脚本,基本上在其中运行三个并行的npm builds命令,如下所示:
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--prod" "-bh" "/$p1.UI_prod/" "-op" "distProd"
} -ArgumentList $BuildName, $Path -Name "First task"
使用不同的参数重复3次。 PowerShell在Azure DevOps中执行,这显然会改变其行为。问题是,当作业失败时,我无法检索错误日志,它仅显示一般错误,如下所示:
但是,当我在本地运行它时,确实会出现错误。我在这里想念什么?这是完整的代码。
param (
[Parameter(Mandatory = $true)]
[string]$BuildName,
[Parameter(Mandatory = $true)]
[string]$Type,
[bool]$SolutionType = $false,
[string]$Path = ''
)
# Determine the type of compilation specified
$Type = $Type.ToLower()
# Each script block starts a parallel job that runs the build.
# Run dev mode
if (($Type -eq 'dev') -or ($Type -eq 'all')) {
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--dev" "-bh" "/$p1.UI/" "-op"
} -ArgumentList $BuildName, $Path -Name "Build UI Dev"
}
# Run prod mode
if (($Type -eq 'prod') -or ($Type -eq 'all')) {
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--prod" "-bh" "/$p1.UI_prod/" "-op" "distProd"
} -ArgumentList $BuildName, $Path -Name "Build UI Prod"
}
# Run BO prod mode
if (($Type -eq 'bo') -or ($Type -eq 'all')) {
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--prod" "--app=1" "-bh" "/$p1.BOUI_prod/" "-op" "distBOProd"
} -ArgumentList $BuildName, $Path -Name "Build UI BO"
}
# Run bots dev mode
if (($Type -eq 'botsdev') -or ($Type -eq 'botsboth')) {
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--prod" "--app=2" "-bh" "/$p1.BotsUI/" "-op" "distBots"
} -ArgumentList $BuildName, $Path -Name "Build Bots UI Dev"
}
# Run bots prod mode
if (($Type -eq 'botsprod') -or ($Type -eq 'botsboth')) {
Start-Job -ScriptBlock { param ($p1, $wf)
Set-Location $wf
node --max-old-space-size=8192 "node_modules/@angular/cli/bin/ng/" "build" "--prod" "--app=2" "-bh" "/$p1.BotsUI_prod/" "-op" "distBotsProd"
} -ArgumentList $BuildName, $Path -Name "Build Bots UI Prod"
}
# Check the status of all jobs every 10 seconds UNTIL there are no jobs in 'Running' state
do {
Start-Sleep -Seconds 10
$completedJobs = Get-Job -State 'Completed' | Where-Object -FilterScript { $_.Name -like '*Build*' }
foreach ($job in $completedJobs) {
# If a job is completed, print the output to the console.
$jobName = $job | Get-Job | Select-Object -ExpandProperty Name
Write-Output "##[section] <<<<<<<<< $jobName completed >>>>>>>>>"
try {
$job | Receive-Job
}
catch {
Write-Output $_.Exception.Message
Write-Output $_.Exception.StackTrace
Write-Output $_.Exception.InnerException
}
$job | Remove-Job
}
# Count the number of jobs still pending for this session
$remainingJobs = Get-Job -State 'Running' | Where-Object -FilterScript { $_.Name -like '*Build*' }
# Count the number of jobs that failed during this session
$failedJobs = Get-Job -State 'Failed' | Where-Object -FilterScript { ($_.Name -like '*Build*') -or $_.HasErrors }
} while ($remainingJobs.Count -ne 0)
# If one job failed, the entire task fails.
# HOWEVER, if the error is *Node#moveTo was deprecated. Use Container#append*, the task is marked as success despite it.
# It's not actually an error, but PowerShell reads it as one.
if ($failedJobs.Count -ne 0) {
foreach ($job in $failedJobs) {
if ($job.Error -like '*Node#moveTo was deprecated. Use Container#append*' -and $job.Error -like '*ERROR*') {
Write-Error $failedJobs
Remove-Job $job
throw;
}
else {
Write-Output $job
Remove-Job $job
}
}
}
Write-Output "##[section] ------------------------------------ Task completed :) ------------------------------------"