3

I am triggering a python script through a Jenkins job, and would print a hyperlink in the Jenkins console output. Is there a Jenkins plugin or python module I can use to achieve this.

From a test script, I tried doing this - echo 'print "http://www.google.com>Google"' but on console output it simply displays that as raw text and not as a hyperlink (It does make the http url link clickable).

I am aware that this will work correctly in case of HTML file

3 Answers 3

2

You may try ANSI Color plugin it shall auto convert it to hyperlink. I tried with java it works, you may try with Python :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the comment. After enabling ANSIColor plugin in Jenkins, I tried a simple statement "printf '<a href=google.com>Google</a>'" and this printed out the entire raw string, instead of printing just Google with the hyperlink. I enabled the plugin from the configure page and have the color map set to default value of xterm. Let me know if I am missing something here.
Hi, please try directly print out google.com as text without the <a>, it shall be automatically covert to hyperlink in your console.
1

Install the anything-goes-formatter

https://wiki.jenkins-ci.org/pages/viewpage.action?pageId=60915753

Enable the Markup formatter on global configuration (security section)

http://127.0.0.1:8080/configureSecurity/

Comments

1

It took me a while to figure this out from Groovy code (jenkinsfile), but I knew there has to be a way as steps/plugins can do it. In this case you need ModelHyperlinkNote (https://javadoc.jenkins-ci.org/hudson/console/ModelHyperlinkNote.html) and its static methods; so for a link to Job started you'd do:

final Run buildRun = Jenkins.instance.getItemByFullName(buildJobName
  ).getBuildByNumber(runId) as Run
final String link = ModelHyperlinkNote.encodeTo(buildRun)

and then you can simply write that value to log and Console Log will interpret it and add widget with all relevant operations.

In addition to type-specific methods, there is general-purpose encodeTo(String url, String text) that allows links to other kinds of entities.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.