Report the Blue Ocean URL on Gerrit presubmit

This URL is easier to visualize with the new job and failure are
easier to browse. Although due to https://issues.jenkins-ci.org/browse/JENKINS-26522
still being worked on, we currently cannot mark a specific step as
"unstable", so all the step appear as unstable when a test fails. In which
case looking at the list of test result might be better, but that's one
click away from the default view in Blue Ocean.

Change-Id: I3d221276380b814cb0bd10fee08fffe16a18ca2c
diff --git a/jenkins/lib/src/build/bazel/ci/JenkinsUtils.groovy b/jenkins/lib/src/build/bazel/ci/JenkinsUtils.groovy
index f917be1..ea25d77 100644
--- a/jenkins/lib/src/build/bazel/ci/JenkinsUtils.groovy
+++ b/jenkins/lib/src/build/bazel/ci/JenkinsUtils.groovy
@@ -91,6 +91,26 @@
     return null
   }
 
+  /** Returns the URL of the console for a job run */
+  static def getConsoleUrl(RunWrapper run) {
+    return "${run.absoluteUrl}console"
+  }
+
+  /** Returns the URL of the blue ocean view for a job run */
+  @NonCPS
+  static def getBlueOceanUrl(RunWrapper run) {
+    def name = java.net.URLEncoder.encode(run.fullProjectName, "UTF-8")
+    def url = new URL(run.absoluteUrl)
+    def path = "/blue/organizations/jenkins/${name}/detail/${run.projectName}/${run.number}/pipeline/"
+    return new URL(url.protocol, url.host, url.port, path).toString()
+  }
+
+  /** Returns the URL to the small icon for a run */
+  @NonCPS
+  static def getSmallIconUrl(RunWrapper run) {
+    return "${Jenkins.RESOURCE_PATH}/images/16x16/${run.rawBuild.getIconColor()}.png"
+  }
+
   /**
    * A utility method that look for an artifact matching a pattern in upstream
    * builds.
diff --git a/jenkins/lib/vars/gerritReview.groovy b/jenkins/lib/vars/gerritReview.groovy
index 7e92f76..cd1064d 100644
--- a/jenkins/lib/vars/gerritReview.groovy
+++ b/jenkins/lib/vars/gerritReview.groovy
@@ -26,7 +26,8 @@
   stage("Start Gerrit review") {
     echo "Reviewing change ${url} (${branch})"
     gerrit.addReviewer(changeNum)
-    gerrit.comment(changeNum, branch, "Starting build at ${currentBuild.getAbsoluteUrl()}")
+    gerrit.comment(changeNum, branch,
+		   "Starting build at ${JenkinsUtils.getBlueOceanUrl(currentBuild)}")
   }
   def config = [gerritBuild: currentBuild]
   try {
@@ -37,6 +38,6 @@
     def verified = result == "SUCCESS" ? "+" : "-"
     echo "Setting ${verified}Verified to change ${url} after build returned ${result}"
     gerrit.review(changeNum, branch, result == "SUCCESS" ? 1 : -1,
-                  "Build ${config.gerritBuild.getAbsoluteUrl()} finished with status ${result}")
+                  "Build ${JenkinsUtils.getBlueOceanUrl(config.gerritBuild)} finished with status ${result}")
   }
 }
diff --git a/jenkins/lib/vars/reportAB.groovy b/jenkins/lib/vars/reportAB.groovy
index 9b61e51..1476e0a 100644
--- a/jenkins/lib/vars/reportAB.groovy
+++ b/jenkins/lib/vars/reportAB.groovy
@@ -19,11 +19,10 @@
   if (run == null) {
     return "unkown status"
   }
-  def consoleUrl = "${run.absoluteUrl}console"
-  def name = java.net.URLEncoder.encode(run.fullProjectName, "UTF-8")
-  def runUrl = "/blue/organizations/jenkins/${name}/detail/${run.projectName}/${run.number}/pipeline/"
-  def resultImg = "${Jenkins.RESOURCE_PATH}/images/16x16/${run.rawBuild.getIconColor()}.png"
-  return "<a href=\"${consoleUrl}\"><img src=\"${resultImg}\"/></a> <a href=\"${runUrl}\">#${run.number}</a>"
+  def console = JenkinsUtils.getConsoleUrl(run)
+  def url = JenkinsUtils.getBlueOceanUrl(run)
+  def icon = JenkinsUtils.getSmallIconUrl(run)
+  return "<a href=\"${console}\"><img src=\"${icon}\"/></a> <a href=\"${url}\">#${run.number}</a>"
 }
 
 @NonCPS