-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsuppress-script-error.yml
107 lines (97 loc) · 2.61 KB
/
suppress-script-error.yml
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: $(Date:yyyyMMdd)$(Rev:.r)-$(Build.DefinitionVersion)-$(SourceBranchName)-$(Build.BuildId)
schedules:
- cron: '0 1 * * *'
displayName: 'Nightly build (UTC)'
always: 'true'
branches:
include:
- main
trigger: none
jobs:
- job: bash
displayName: Suppress script errors in bash
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
echo This step will fail
>&2 echo "error"
condition: always()
continueOnError: true
displayName: 'Fail on stderr'
failOnStderr: true
- bash: |
echo This step will not fail
>&2 echo "error"
condition: always()
displayName: 'Not failing on stderr'
failOnStderr: false
- bash: |
echo This step will fail on non-zero exit code
bash -c 'exit 1'
condition: always()
continueOnError: true
displayName: 'Fail on non-zero exit code'
- bash: |
echo This step will not fail on non-zero exit code
bash -c 'exit 1'
if [ $? -eq 1 ]
then
echo Absorbing exit code 1
exit 0
else
exit $?
fi
condition: always()
displayName: 'Not failing on non-zero exit code'
- job: pwsh
displayName: Suppress script errors in PowerShell
pool:
vmImage: 'ubuntu-latest'
steps:
- pwsh: |
Write-Host "This step will fail"
bash -c '>&2 echo "error"'
condition: always()
continueOnError: true
displayName: 'Fail on stderr'
failOnStderr: true
- pwsh: |
Write-Host "This step will not fail (failOnStderr)"
bash -c '>&2 echo "error"'
condition: always()
displayName: 'Not failing on stderr'
failOnStderr: false
- pwsh: |
Write-Host "This step will fail"
Write-Error "This message is processed by error stream"
condition: always()
continueOnError: true
displayName: 'Fail on Write-Error'
errorActionPreference: stop
- pwsh: |
Write-Host "This step will not fail (errorActionPreference)"
Write-Error "This message is processed by error stream"
condition: always()
displayName: 'Not failing on Write-Error'
errorActionPreference: silentlyContinue
- pwsh: |
Write-Host "This step will fail on non-zero exit code"
pwsh -nop -c 'exit 1'
condition: always()
displayName: 'Fail on non-zero exit code'
continueOnError: true
- pwsh: |
Write-Host "This step will not fail on non-zero exit code"
pwsh -nop -c 'exit 1'
if ($LastExitCode -eq 1)
{
Write-Host "Absorbing exit code 1"
exit 0
}
else
{
exit $LastExitCode
}
condition: always()
displayName: 'Not failing on non-zero exit code'