Enable output console to work with Jenkins thread / child to start task console launch

2 Jenkins Works: A and B.

A starts B as a stage of blocking the assembly ("Block until running projects complete their assemblies"). Is there a way to include console output B in console output?

Motivation: for use by the Jenkins browser. The console output contains a link to console output B, which is great. But when using Jenkins through command line tools (jenkins-cli) there is no quick and easy way to see console output B.

Any ideas?

+3
source share
2 answers

Interesting. I would try something like this.

From http://jenkinsurl/job/jobname/lastBuild/api/


, GET . GET URL- ( URL-, , HTML .) , .

, X-Text-Size, ( ). , .

X-More-Data: true, , , . Jenkins 5 . , , , .

, , " ". (execute shell, ) script, , , . , , X-More-Data: true, .

+1

, , . , - . Groovy script, URL- progressiveText. , . jenkinsBase jobName. , .

, : (1) , . (2) Trigger/call , . (3) " , ". (4) Execute Groovy script :

def jenkinsBase = // Set to Jenkins base URL here
def jobName = // Set to jenkins job name 
def jobNumber = 'lastBuild' // Tail last build
def address = null
def response = null
def start = 0 // Start at offset 0
def cont = true // This semaphore holds the value of X-More-Data header value
try {
    while (cont == true) { // Loop while X-More-Data value is equal to true
    address = "${jenkinsBase}/job/${jobName}/${jobNumber}/logText/progressiveText?start=${start}"
    def urlInfo = address.toURL()
    response = urlInfo.openConnection()
    if (response.getResponseCode() != 200) {
        throw new Exception("Unable to connect to " + address) // Throw an exception to get out of loop if response is anything but 200
    }
    if (start != response.getHeaderField('X-Text-Size')) { // Print content if the starting offset is not equal the value of X-Text-Size header
      response.getInputStream().getText().eachLine { line ->
        println(line)
      }  
    }
    start = response.getHeaderField('X-Text-Size') // Set new start offset to next byte
    cont = response.getHeaderField('X-More-Data') // Set semaphore to value of X-More-Data field. If this is anything but true, we will fall out of    while loop
    sleep(3000) // wait for 3 seconds 
  }
}
catch (Exception ex) {
  println (ex.getMessage()) 
}

script .

Python .

0

Source: https://habr.com/ru/post/1598730/


All Articles