简体   繁体   中英

Jenkins: print a Hyperlink (HyperlinkNote) in console output from a script

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM