How to display a hyperlink in hudson/jenkins build output console
Asked Answered
D

2

12

How do I display a hyperlink (weblink) in hudson/jenkins build output console?

What I'm trying to achieve is, during a hudson/jenkins build based on certain condition, I would like to display a hyperlink. When a user click on that link, it should open a new browser window and show the page.

Is there a plugin to do this? Any suggestions please?

Delinda answered 1/11, 2015 at 1:23 Comment(1)
forgot to mention, would like to dynamically construct the url context based on the conditionDelinda
B
6

If you enter, for example:

echo 'http://example.com'

in a Build step Execute shell → Command the address will be hyperlinked in the Console Output, though not with target="_blank". But middle-clicking on it opens it in a new tab or window – depending on your browser preferences.

Brei answered 1/11, 2015 at 2:23 Comment(2)
Thanks that helped. Is it possible to have href. e.g Text would show "click here" but underline endpoint would be an actual URL. Just dont want to show full URL. ...I"m trying but not able to get it :)Delinda
@Delinda Unfortunately it isn't. <a href="...">...</a> is printed as plain text with just the content of href hyperlinked. And, BTW, „click here“ isn't a good link text anyway. The text should cover what can be expected to be found when following the link, not how to follow it. The latter is known by any browser user anyway. And it's not just clicking: it can be tapping with a stylus or just a finger or tabbing to it and hitting <Enter>.Brei
D
13

When using a (system) groovy script or Jenkins job pipeline (without sandbox) you may want to try e.g.:

import hudson.console.ModelHyperlinkNote
println hudson.console.ModelHyperlinkNote.encodeTo('http://example.com', 'example')

Please find the full API of hudson.console.ModelHyperlinkNote here: http://javadoc.jenkins-ci.org/hudson/console/ModelHyperlinkNote.html

Dial answered 4/8, 2017 at 8:56 Comment(1)
That's it! Solved the problem I had -- esp. worth noting it has special handling for Job, Build, User and Node, in addition to general purpose method mentioned here.Stylopodium
B
6

If you enter, for example:

echo 'http://example.com'

in a Build step Execute shell → Command the address will be hyperlinked in the Console Output, though not with target="_blank". But middle-clicking on it opens it in a new tab or window – depending on your browser preferences.

Brei answered 1/11, 2015 at 2:23 Comment(2)
Thanks that helped. Is it possible to have href. e.g Text would show "click here" but underline endpoint would be an actual URL. Just dont want to show full URL. ...I"m trying but not able to get it :)Delinda
@Delinda Unfortunately it isn't. <a href="...">...</a> is printed as plain text with just the content of href hyperlinked. And, BTW, „click here“ isn't a good link text anyway. The text should cover what can be expected to be found when following the link, not how to follow it. The latter is known by any browser user anyway. And it's not just clicking: it can be tapping with a stylus or just a finger or tabbing to it and hitting <Enter>.Brei

© 2022 - 2024 — McMap. All rights reserved.