@@ -54,35 +54,32 @@ function getExecOptions(): tr.IExecOptions {
54
54
* @param args Arguments to execute via mvn
55
55
* @returns execution Status Code
56
56
*/
57
- export async function execMavenBuild ( args : string [ ] ) {
58
-
57
+ export async function execMavenBuild ( args : string [ ] ) : Promise < number > {
59
58
var mvnExec = getMavenExec ( ) ;
60
59
61
60
// Setup tool runner that executes Maven only to retrieve its version
62
61
var mvnGetVersion = tl . tool ( mvnExec ) ;
63
62
mvnGetVersion . arg ( '-version' ) ;
64
63
65
- // 1. Check that Maven exists by executing it to retrieve its version.
66
- await mvnGetVersion . exec ( )
67
- . fail ( function ( err ) {
68
- console . error ( "Maven is not installed on the agent" ) ;
69
- tl . setResult ( tl . TaskResult . Failed , "Maven is not installed." ) ; // tl.exit sets the step result but does not stop execution
70
- process . exit ( 1 ) ;
71
- } )
72
- . then ( async function ( code ) {
73
- // Setup Maven Executable to run list of test runs provided as input
74
- var mvnRun = tl . tool ( mvnExec ) ;
75
- mvnRun . arg ( '-ntp' ) ;
76
- mvnRun . arg ( args ) ;
77
-
78
- // 3. Run Maven. Compilation or test errors will cause this to fail.
79
- return mvnRun . exec ( getExecOptions ( ) ) ;
80
- } )
81
- . fail ( function ( err ) {
82
- console . error ( err . message ) ;
83
- tl . setResult ( tl . TaskResult . Failed , "Build failed." ) ; // tl.exit sets the step result but does not stop execution
84
- process . exit ( 1 ) ;
85
- } ) ;
64
+ try {
65
+ // 1. Check that Maven exists by executing it to retrieve its version.
66
+ await mvnGetVersion . exec ( ) ;
67
+
68
+ // Setup Maven Executable to run list of test runs provided as input
69
+ var mvnRun = tl . tool ( mvnExec ) ;
70
+ mvnRun . arg ( '-ntp' ) ;
71
+ mvnRun . arg ( args ) ;
72
+
73
+ // 3. Run Maven. Compilation or test errors will cause this to fail.
74
+ await mvnRun . exec ( getExecOptions ( ) ) ;
75
+
76
+ // Maven build succeeded
77
+ return 0 ; // Return 0 indicating success
78
+ } catch ( err ) {
79
+ console . error ( err . message ) ;
80
+ tl . setResult ( tl . TaskResult . Failed , "Build failed." ) ;
81
+ return 1 ; // Return 1 indicating failure
82
+ }
86
83
}
87
84
88
85
function getGradlewExec ( ) {
@@ -105,14 +102,16 @@ function getGradlewExec() {
105
102
106
103
if ( gradlewPath . length == 0 ) {
107
104
tl . setResult ( tl . TaskResult . Failed , "Missing gradlew file" ) ;
105
+ return "" ;
108
106
}
109
107
108
+ var gradlewExec : string = gradlewPath [ 0 ] ;
109
+
110
110
if ( gradlewPath . length > 1 ) {
111
111
tl . warning ( tl . loc ( 'MultipleMatchingGradlewFound' ) ) ;
112
+ tl . debug ( gradlewExec ) ;
112
113
}
113
114
114
- var gradlewExec : string = gradlewPath [ 0 ] ;
115
-
116
115
if ( isWindows ) {
117
116
tl . debug ( 'Append .bat extension name to gradlew script.' ) ;
118
117
gradlewExec += '.bat' ;
@@ -136,22 +135,27 @@ function getGradlewExec() {
136
135
* @param args Arguments to execute via mvn
137
136
* @returns execution Status Code
138
137
*/
139
- export async function execGradleBuild ( args : string [ ] ) {
138
+ export async function execGradleBuild ( args : string [ ] ) : Promise < number > {
140
139
var gradleExec = getGradlewExec ( ) ;
141
140
142
- // Setup tool runner that executes Maven only to retrieve its version
141
+ if ( ! gradleExec || gradleExec == "" ) {
142
+ return 1 ; // Return 1 indicating failure
143
+ }
144
+
145
+ // Setup tool runner that executes Gradle
143
146
var gradleRunner = tl . tool ( gradleExec ) ;
144
147
145
148
// Add args prepared by invoker for executing individual test cases
146
149
gradleRunner . arg ( 'clean' ) ;
147
150
gradleRunner . arg ( args ) ;
148
151
149
- var statusCode = await gradleRunner . exec ( getExecOptions ( ) )
150
- . fail ( function ( err ) {
151
- console . error ( err . message ) ;
152
- tl . setResult ( tl . TaskResult . Failed , "Build failed." ) ; // tl.exit sets the step result but does not stop execution
153
- process . exit ( 1 ) ;
154
- } ) ;
155
-
156
- return statusCode ;
152
+ try {
153
+ await gradleRunner . exec ( getExecOptions ( ) ) ;
154
+ // Gradle build succeeded
155
+ return 0 ; // Return 0 indicating success
156
+ } catch ( err ) {
157
+ console . error ( err . message ) ;
158
+ tl . setResult ( tl . TaskResult . Failed , "Build failed." ) ; // Set the step result to Failed
159
+ return 1 ; // Return 1 indicating failure
160
+ }
157
161
}
0 commit comments