@@ -41,16 +41,51 @@ async function main() {
41
41
const disabledPipelines : string [ ] = [ ] ;
42
42
const invalidPipelines : string [ ] = [ ] ;
43
43
const runningTestBuilds : Promise < BuildResult | BuildResult [ ] > [ ] = [ ] ;
44
+
45
+ // Fetch all pipelines once at the start for efficiency
46
+ const pipelines = await fetchPipelines ( ) ( ) ;
47
+
48
+ // Add null check and array validation
49
+ if ( ! pipelines || ! Array . isArray ( pipelines ) ) {
50
+ console . error ( 'Failed to fetch pipelines or pipelines is not an array' ) ;
51
+ console . log ( '##vso[task.complete result=Failed]' ) ;
52
+ process . exit ( 1 ) ;
53
+ }
54
+
55
+ // Add length check
56
+ if ( pipelines . length === 0 ) {
57
+ console . warn ( 'No pipelines found in the project' ) ;
58
+ console . log ( '##vso[task.issue type=warning]No pipelines found in the project' ) ;
59
+ console . log ( '##vso[task.complete result=Succeeded]' ) ;
60
+ process . exit ( 0 ) ;
61
+ }
62
+
63
+ console . log ( `Found ${ pipelines . length } total pipelines in the project` ) ;
64
+
44
65
for ( const task of api . tasks ) {
45
66
console . log ( `starting tests for ${ task } task` ) ;
46
- const runResult = await runTaskPipelines ( task ) ;
47
67
48
- if ( runResult === DISABLED ) {
49
- disabledPipelines . push ( task ) ;
50
- } else if ( runResult === INVALID ) {
51
- invalidPipelines . push ( task ) ;
68
+ // Find all pipelines that start with the task name
69
+ const matchingPipelines = pipelines . filter ( pipeline => pipeline . name ?. startsWith ( task ) ) ;
70
+
71
+ if ( matchingPipelines . length > 0 ) {
72
+ console . log ( `Found ${ matchingPipelines . length } pipeline(s) for task "${ task } ": ${ matchingPipelines . map ( p => p . name ) . join ( ', ' ) } ` ) ;
73
+
74
+ for ( const pipeline of matchingPipelines ) {
75
+ console . log ( `\n--- Starting pipeline execution: ${ task } on ${ pipeline . name } ---` ) ;
76
+
77
+ const runResult = await runTaskPipelines ( task , pipeline ) ;
78
+
79
+ if ( runResult === DISABLED ) {
80
+ disabledPipelines . push ( `${ task } (${ pipeline . name } )` ) ;
81
+ } else if ( runResult === INVALID ) {
82
+ invalidPipelines . push ( `${ task } (${ pipeline . name } )` ) ;
83
+ } else {
84
+ runningTestBuilds . push ( ...runResult ) ;
85
+ }
86
+ }
52
87
} else {
53
- runningTestBuilds . push ( ... runResult ) ;
88
+ console . log ( `Cannot build and run tests for task ${ task } - corresponding test pipeline was not found` ) ;
54
89
}
55
90
}
56
91
@@ -101,12 +136,9 @@ async function main() {
101
136
}
102
137
103
138
// Running test pipelines for task by build configs
104
- async function runTaskPipelines ( taskName : string ) : Promise < Promise < BuildResult | BuildResult [ ] > [ ] | typeof DISABLED | typeof INVALID > {
105
- const pipelines = await fetchPipelines ( ) ( ) ;
106
- const pipeline = pipelines . find ( pipeline => pipeline . name === taskName ) ;
139
+ async function runTaskPipelines ( taskName : string , pipeline : BuildDefinitionReference ) : Promise < Promise < BuildResult | BuildResult [ ] > [ ] | typeof DISABLED | typeof INVALID > {
107
140
let allowParrallelRun = true ;
108
141
109
- if ( pipeline ) {
110
142
if ( pipeline . queueStatus === 2 ) { // disabled
111
143
console . log ( `Pipeline "${ pipeline . name } " is disabled.` ) ;
112
144
return DISABLED ;
@@ -155,7 +187,6 @@ async function runTaskPipelines(taskName: string): Promise<Promise<BuildResult |
155
187
console . log ( `Running tests for "${ taskName } " task with config "${ config } " for pipeline "${ pipeline . name } "` ) ;
156
188
const pipelineBuild = await startTestPipeline ( pipeline , config ) ;
157
189
if ( pipelineBuild !== null ) {
158
-
159
190
result = await completeBuild ( taskName , pipelineBuild ) ;
160
191
buildResults . push ( result ) ;
161
192
}
@@ -164,13 +195,7 @@ async function runTaskPipelines(taskName: string): Promise<Promise<BuildResult |
164
195
} ) ) ;
165
196
}
166
197
167
-
168
198
return runningBuilds ;
169
- }
170
-
171
- console . log ( `Cannot build and run tests for task ${ taskName } - corresponding test pipeline was not found` ) ;
172
-
173
- return [ ] ;
174
199
}
175
200
176
201
async function startTestPipeline ( pipeline : BuildDefinitionReference , config = '' ) : Promise < Build | null > {
0 commit comments