13
13
* @param config Mock configuration name to check in
14
14
* @param allow_errors Whether errors are allowd. Defaults to false.
15
15
*/
16
- String warnings (String output ) {
17
- return extract(output, ' warnings' )
18
- }
19
-
20
- String errors (String output ) {
21
- return extract(output, ' errors' )
22
- }
23
-
24
- String extract (String output , String type ) {
25
- /* groovylint-disable-next-line VariableName */
26
- String T
27
- if (type == ' errors' ) {
28
- T = ' E'
29
- } else if (type == ' warnings' ) {
30
- T = ' W'
31
- } else {
32
- error(" Unsupported type ${ type} passed to extract()" )
33
- }
34
-
35
- return sh(label : " Extract ${ type} from rpmlint output" ,
36
- script : " echo \" ${ output} \" | grep ': ${ T} : '" ,
37
- returnStdout : true ). trim()
38
- }
39
-
40
16
/* groovylint-disable-next-line ParameterName */
41
17
void call (String config , Boolean allow_errors = false , Boolean skip_rpmlint = false , String make_args = ' ' ) {
42
18
if (skip_rpmlint || config == ' not_applicable' ) {
@@ -47,50 +23,32 @@ void call(String config, Boolean allow_errors=false, Boolean skip_rpmlint=false,
47
23
if (fileExists(' utils/rpms/Makefile' )) {
48
24
chdir = ' utils/rpms/'
49
25
}
50
- String output = sh(label : ' RPM Lint built RPMs' ,
51
- script : ' cd ' + chdir + ' \n ' +
26
+ int result = sh(label : ' RPM Lint built RPMs' ,
27
+ script : ' cd ' + chdir + ' \n ' +
52
28
/* groovylint-disable-next-line GStringExpressionWithinString */
53
29
''' name=$(make ''' + make_args + ''' show_NAME)
54
30
if [ -f "$name".rpmlintrc ]; then
55
31
rpmlint_args=(-r "$name".rpmlintrc)
56
32
fi
57
33
rpmlint --ignore-unused-rpmlintrc "${rpmlint_args[@]}" ''' +
58
34
' $(ls /var/lib/mock/' + config + ' /result/*.rpm | ' +
59
- ' grep -v -e -debuginfo -e debugsource) || exit 0' ,
60
- returnStdout : true ). trim()
61
-
62
- int result = sh(label : ' Analyze rpmlint output' ,
63
- script : " read e w b < <(echo \" ${ output} \" | " +
64
- """ sed -nEe '\$ s/.*([0-9]+) errors, ([0-9]+) warnings, ([0-9]+) badness;.*/\\ 1 \\ 2 \\ 3/p')
65
- if [ "\$ e" -gt 0 ]; then
66
- exit 2
67
- elif [ "\$ w" -gt 0 ]; then
68
- exit 1
69
- fi
70
- exit 0""" ,
35
+ ' grep -v -e -debuginfo -e debugsource)' ,
71
36
returnStatus : true )
72
37
73
38
catchError(stageResult : ' UNSTABLE' , buildResult : ' SUCCESS' ) {
74
- if (result == 2 && allow_errors) {
75
- error(' RPM Lint found errors, but allow_errors is ' + allow_errors + ' :\n ' +
76
- errors(output) + ' \n\n ' +
77
- ' And also found additional warnings that it would be nice to fix:\n ' + warnings(output))
78
- } else if (result == 1 ) {
79
- error(' RPM Lint found warnings:\n ' + warnings(output))
39
+ if (result > 0 && allow_errors) {
40
+ error(' RPM Lint found errors, but allow_errors is true.' )
80
41
}
81
- return
82
42
}
83
43
84
44
catchError(stageResult : ' UNSTABLE' , buildResult : ' UNSTABLE' ) {
85
- if (result == 2 && ! allow_errors) {
86
- error(' RPM Lint found errors:\n ' + errors(output) + ' \n\n ' +
87
- ' And also found additional warnings that it would be nice to fix:\n ' + warnings(output))
45
+ if (result > 0 && ! allow_errors) {
46
+ error(' RPM Lint found errors.' )
88
47
}
89
- return
90
48
}
91
49
92
- // the returns above in the catchError() blocks don't acutally seem to work
50
+ // Print success message if rpmlint exits with 0
93
51
if (result == 0 ) {
94
- echo( ' RPM Lint output: \n ' + output)
52
+ echo ' RPM Lint passed with no errors or warnings. '
95
53
}
96
54
}
0 commit comments