public void streamConsoleOutput ( final BuildConsoleStreamListener listener , final int poolingInterval , final int poolingTimeout , boolean crumbFlag ) throws InterruptedException , IOException { // Calculate start and timeout final long startTime = System . currentTimeMillis ( ) ; final long timeoutTime = startTime + ( poolingTimeout * 1000 ) ; int bufferOffset = 0 ; while ( true ) { Thread . sleep ( poolingInterval * 1000 ) ; ConsoleLog consoleLog = null ; consoleLog = getConsoleOutputText ( bufferOffset , crumbFlag ) ; String logString = consoleLog . getConsoleLog ( ) ; if ( logString != null && ! logString . isEmpty ( ) ) { listener . onData ( logString ) ; } if ( consoleLog . getHasMoreData ( ) ) { bufferOffset = consoleLog . getCurrentBufferSize ( ) ; } else { listener . finished ( ) ; break ; } long currentTime = System . currentTimeMillis ( ) ; if ( currentTime > timeoutTime ) { LOGGER . warn ( "Pooling for build {0} for {2} timeout! Check if job stuck in jenkins" , BuildWithDetails . this . getDisplayName ( ) , BuildWithDetails . this . getNumber ( ) ) ; break ; } } }
Stream build console output log as text using BuildConsoleStreamListener Method can be used to asynchronously obtain logs for running build .