How to get console output of downstream job in upstream job? How to get console output of downstream job in upstream job? powershell powershell

How to get console output of downstream job in upstream job?


I solved my problem by adding this into the cycle. I could get log of downstrema jobs into upstream, display it and work with it.

def checkjob = build job: 'job name', parameters: [ any params here]checklog = Jenkins.getInstance().getItemByFullName('job name').getBuildByNumber(checkjob.getNumber()).logprintln checklog


A shorter alternative:

def result = build job: 'job_name', wait: trueprintln result.getRawBuild().getLog()

It will be necessary to whitelist both methods.

Edit: since you don't want to wait for the build to run, you could add this at the end of your job (or at some point after all triggered builds should be finished) where number_of_builds in your case will be servers.size().

def job = Jenkins.getInstance().getItemByFullName('job_A_name')def last_build = job.getLastBuild().getNumber()def first_build = last_build - number_of_builds(first_build..last_build).each {    println "Log of build $it"    def build = job.getBuildByNumber(it)    println build.log}

If you really want to be sure the builds you're getting are the ones triggered by your job, you can get the build cause from the build object.


Here's a silly example:

$myJobs = @()$myJobs += Start-job -ScriptBlock { while (1) {Get-Item 'c:\*'; sleep 5}}$myJobs += Start-job -ScriptBlock { while (1) {Get-Item 'c:\windows\*'; sleep 5}}try {    while(1)    {        $myJobs | Get-Job -HasMoreData $true | Receive-Job    }} finally {    $myJobs | Stop-Job    $myJobs | Remove-Job}

Anything the job pipelines is queued. The -HasMoreData state indicates that the job has output that is available to read. The parent receives the output using Receive-Job. By default it displays in the console, but you can receive the output in the parent process and do further processing.

If this isn't what you're going for you'll have to be more specific in your question. Provide a little of the code you've tried so far.