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?

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
enthuguy
  • 405
  • 2
  • 8
  • 20

2 Answers2

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

bschlueter
  • 3,817
  • 1
  • 30
  • 48
Joerg S
  • 4,730
  • 3
  • 24
  • 43
  • 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. – StaxMan Mar 07 '19 at 21:32
5

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • 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 :) – enthuguy Nov 01 '15 at 04:30
  • 1
    @enthuguy Unfortunately it isn't. `...` 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 . – Gerold Broser Nov 01 '15 at 12:05