@@ -41,16 +41,51 @@ async function main() {
4141 const disabledPipelines : string [ ] = [ ] ;
4242 const invalidPipelines : string [ ] = [ ] ;
4343 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+
4465 for ( const task of api . tasks ) {
4566 console . log ( `starting tests for ${ task } task` ) ;
46- const runResult = await runTaskPipelines ( task ) ;
4767
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+ }
5287 } else {
53- runningTestBuilds . push ( ... runResult ) ;
88+ console . log ( `Cannot build and run tests for task ${ task } - corresponding test pipeline was not found` ) ;
5489 }
5590 }
5691
@@ -101,12 +136,9 @@ async function main() {
101136}
102137
103138// 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 > {
107140 let allowParrallelRun = true ;
108141
109- if ( pipeline ) {
110142 if ( pipeline . queueStatus === 2 ) { // disabled
111143 console . log ( `Pipeline "${ pipeline . name } " is disabled.` ) ;
112144 return DISABLED ;
@@ -155,7 +187,6 @@ async function runTaskPipelines(taskName: string): Promise<Promise<BuildResult |
155187 console . log ( `Running tests for "${ taskName } " task with config "${ config } " for pipeline "${ pipeline . name } "` ) ;
156188 const pipelineBuild = await startTestPipeline ( pipeline , config ) ;
157189 if ( pipelineBuild !== null ) {
158-
159190 result = await completeBuild ( taskName , pipelineBuild ) ;
160191 buildResults . push ( result ) ;
161192 }
@@ -164,13 +195,7 @@ async function runTaskPipelines(taskName: string): Promise<Promise<BuildResult |
164195 } ) ) ;
165196 }
166197
167-
168198 return runningBuilds ;
169- }
170-
171- console . log ( `Cannot build and run tests for task ${ taskName } - corresponding test pipeline was not found` ) ;
172-
173- return [ ] ;
174199}
175200
176201async function startTestPipeline ( pipeline : BuildDefinitionReference , config = '' ) : Promise < Build | null > {
0 commit comments