1
votes

When we add a post build action of "Build other project" Jenkins will put a smart link to that build in console output.

I cat the log file of a build (/var/Jenkins/jobs/job1/builds/1/log) and realized that link is in fact a string of bytes. My question is how can I generate such string from a python script that Jenkins run?

(I know I can print http://myjenkins.com/job1 and Jenkins will turn it to a link. but I want to have a Jenkins-like link)

1
your question is not clear: 1.where exactly you want this python script to run from? is it from the job? 2. where do you want it to print the link to? 3. what do you mean by "Jenkins-like" link?Tidhar Klein Orbach

1 Answers

0
votes

I think you are after this:

import hudson.console.*
String getHyperlink(String url, String text) {
    return hudson.console.ModelHyperlinkNote.encodeTo(url, text)
}
println getHyperlink('http://myurl.com', 'linkText')

this will generate the encoded string that can be printed in the console

In this case, this generates:

[8mha:////4NFwoQVOoX5oFqAB5LRT6AEbVT9priUOFDfXahNHEtv7AAAAmh+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAyOEgaBjJKSAit9/dxKoJFAPbkAmUKP18UAAAA=[0mlinkText

that will be printed in the job console as:

lnikText