问题
I'm struggling to get a build with yarn working on azure pipelines build. I'm running on a self hosted windows 10 machine, with Node 8 and Yarn 1.13.
My pipeline definition can be boiled down to:
steps:
- powershell: |
yarn install --frozen-lockfile
and the output I'm getting is
##[section]Starting: PowerShell
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Windows, macOS, or Linux.
Version : 2.140.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
##[command]"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\24a48e14-3107-454e-bb0b-28c377addce3.ps1'"
yarn install v1.13.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.7: The platform "win32" is incompatible with this module.
info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
##[error]yarn : warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
##[error]At C:\agent\_work\_temp\24a48e14-3107-454e-bb0b-28c377addce3.ps1:3 char:1
##[error]+ yarn install --frozen-lockfile
##[error]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[error] + CategoryInfo : NotSpecified: (warning " > boo...ery@1.9.1 - 3".:String) [], RemoteException
##[error] + FullyQualifiedErrorId : NativeCommandError
##[error]
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell
I'm expecting to get many unmet peer dependency warnings (bootstrap is just the first of many) (and it's basically impossible to resolve them by installing the correct packages since they are mutually exclusive - e.g. webpack stylelint hasnt been correctly updated for half a year)
I've tried redirecting stderr to a file, since yarn logs the error as a warning (source) and that uses stderr (source)
steps:
- powershell: |
yarn install --frozen-lockfile 2>err.txt
but that produces the same output, and err.txt is empty.
I also tried capturing the output into a variable, but it still writes the error
steps:
- powershell: |
$foo = yarn install --frozen-lockfile 2>err.txt
produces:
##[section]Starting: PowerShell
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Windows, macOS, or Linux.
Version : 2.140.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
##[command]"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\743ab1e7-3b9a-4659-89b9-7320da0ea69a.ps1'"
##[error]yarn : warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
##[error]At C:\agent\_work\_temp\743ab1e7-3b9a-4659-89b9-7320da0ea69a.ps1:3 char:8
##[error]+ $foo = yarn install --frozen-lockfile 2>err.txt
##[error]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[error] + CategoryInfo : NotSpecified: (warning " > boo...ery@1.9.1 - 3".:String) [], RemoteException
##[error] + FullyQualifiedErrorId : NativeCommandError
##[error]
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell
As requested, redirecting stderr to stdout doesnt work either:
steps:
- powershell: |
$foo = yarn install --frozen-lockfile 2>&1
or
steps:
- powershell: |
yarn install --frozen-lockfile 2>&1 | Out-Null
produces:
##[section]Starting: PowerShell
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Windows, macOS, or Linux.
Version : 2.140.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
##[command]"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\e34f54b3-f15e-426c-aa65-1476ed3d3d34.ps1'"
##[error]yarn : warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
##[error]At C:\agent\_work\_temp\e34f54b3-f15e-426c-aa65-1476ed3d3d34.ps1:3 char:8
+ $foo = yarn install --frozen-lockfile 2>&1
##[error]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[error] + CategoryInfo : NotSpecified: (warning " > boo...ery@1.9.1 - 3".:String) [], RemoteException
##[error] + FullyQualifiedErrorId : NativeCommandError
##[error]
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell
回答1:
I had the same Problem:
for me the solution was to change it from
steps:
- powershell: yarn install
to
steps:
- script: yarn install
回答2:
From https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops
# PowerShell
# Run a PowerShell script on Linux, macOS, or Windows
- task: PowerShell@2
inputs:
#targetType: 'filePath' # Optional. Options: filePath, inline
#filePath: # Required when targetType == FilePath
#arguments: # Optional
#script: '# Write your PowerShell commands here.Write-Host Hello World' # Required when targetType == Inline
#errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue
#failOnStderr: false # Optional
#ignoreLASTEXITCODE: false # Optional
#pwsh: false # Optional
#workingDirectory: # Optional
You can use this to set failOnStderr: false.
回答3:
You should set Powershell Task.input.errorActionPreference to Continue. It defaults to Stop which causes powershell to throw exception on first error emitted into the stream.
This is code taken from our pipeline yml
Write-Host "Set ErrorAction=Continue. Previous value: $ErrorActionPreference"
$prev = $ErrorActionPreference
$ErrorActionPreference="Continue"
try {
& yarn --pure-lockfile *>&1 | ForEach-Object {
$obj = $_
if ( $obj -is [System.Management.Automation.ErrorRecord] ) {
$s = $obj.Exception.Message
}
else {
$s = $obj.ToString()
}
if ( $s.Contains('error') ) {
Write-Error $s
}
elseif ($s.Contains('warning')) {
Write-Warning $s
}
else {
Write-Host $s
}
}
}
finally {
$ErrorActionPreference = $prev
}
$LASTEXITCODE = 0
We actually redirect all streams to default one, and then process messages one by one to detect only errors which sent to agent for fail tasks
来源:https://stackoverflow.com/questions/55125027/ignore-yarn-missing-unmet-dependencies-warning-in-azure-pipelines