public static boolean execute ( AbstractBuild build , BuildListener listener ) { PrintStream logger = listener . getLogger ( ) ; // Check all downstream Project of the project, not just those defined by BuildTrigger // TODO this may not yet be up to date if rebuildDependencyGraphAsync has been used; need a method to wait for the last call made before now to finish final DependencyGraph graph = Jenkins . getInstance ( ) . getDependencyGraph ( ) ; List < Dependency > downstreamProjects = new ArrayList <> ( graph . getDownstreamDependencies ( build . getProject ( ) ) ) ; // Sort topologically downstreamProjects . sort ( new Comparator < Dependency > ( ) { public int compare ( Dependency lhs , Dependency rhs ) { // Swapping lhs/rhs to get reverse sort: return graph . compare ( rhs . getDownstreamProject ( ) , lhs . getDownstreamProject ( ) ) ; } } ) ; for ( Dependency dep : downstreamProjects ) { List < Action > buildActions = new ArrayList <> ( ) ; if ( dep . shouldTriggerBuild ( build , listener , buildActions ) ) { AbstractProject p = dep . getDownstreamProject ( ) ; // Allow shouldTriggerBuild to return false first, in case it is skipping because of a lack of Item.READ/DISCOVER permission: if ( p . isDisabled ( ) ) { logger . println ( Messages . BuildTrigger_Disabled ( ModelHyperlinkNote . encodeTo ( p ) ) ) ; continue ; } boolean scheduled = p . scheduleBuild ( p . getQuietPeriod ( ) , new UpstreamCause ( ( Run ) build ) , buildActions . toArray ( new Action [ 0 ] ) ) ; if ( Jenkins . getInstance ( ) . getItemByFullName ( p . getFullName ( ) ) == p ) { String name = ModelHyperlinkNote . encodeTo ( p ) ; if ( scheduled ) { logger . println ( Messages . BuildTrigger_Triggering ( name ) ) ; } else { logger . println ( Messages . BuildTrigger_InQueue ( name ) ) ; } } // otherwise upstream users should not know that it happened } } return true ; }
Convenience method to trigger downstream builds .