diff --git a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/AbstractWebHookTriggerHandler.java b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/AbstractWebHookTriggerHandler.java index 13b1470..6dfbe23 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/AbstractWebHookTriggerHandler.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/AbstractWebHookTriggerHandler.java @@ -17,12 +17,12 @@ import hudson.model.Job; import hudson.plugins.git.GitSCM; import hudson.plugins.git.RevisionParameterAction; import hudson.scm.SCM; -import jenkins.model.Jenkins; import jenkins.model.ParameterizedJobMixIn; import jenkins.triggers.SCMTriggerItem; import net.karneim.pojobuilder.GeneratePojoBuilder; import org.apache.commons.lang.StringUtils; import org.eclipse.jgit.transport.URIish; +import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider; import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; @@ -69,8 +69,7 @@ public abstract class AbstractWebHookTriggerHandler implement if (client == null) { LOGGER.log(Level.SEVERE, "No GitLab connection configured"); } else { - String targetUrl = - Jenkins.getInstance().getRootUrl() + job.getUrl() + job.getNextBuildNumber() + "/"; + String targetUrl = DisplayURLProvider.get().getJobURL(job); client.changeBuildStatus(buildStatusUpdate.getProjectId(), buildStatusUpdate.getSha(), BuildState.pending, buildStatusUpdate.getRef(), buildName, targetUrl, BuildState.pending.name()); } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/OpenMergeRequestPushHookTriggerHandler.java b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/OpenMergeRequestPushHookTriggerHandler.java index 30eef62..6a71b31 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/OpenMergeRequestPushHookTriggerHandler.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/OpenMergeRequestPushHookTriggerHandler.java @@ -21,11 +21,11 @@ import hudson.model.CauseAction; import hudson.model.Job; import hudson.plugins.git.RevisionParameterAction; import hudson.triggers.Trigger; -import jenkins.model.Jenkins; import jenkins.model.ParameterizedJobMixIn; import jenkins.model.ParameterizedJobMixIn.ParameterizedJob; import org.apache.commons.lang.StringUtils; import org.eclipse.jgit.transport.URIish; +import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider; import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; @@ -159,7 +159,7 @@ class OpenMergeRequestPushHookTriggerHandler implements PushHookTriggerHandler { if (StringUtils.isNotBlank(buildName)) { GitLabClient client = job.getProperty(GitLabConnectionProperty.class).getClient(); try { - String targetUrl = Jenkins.getInstance().getRootUrl() + job.getUrl() + job.getNextBuildNumber() + "/"; + String targetUrl = DisplayURLProvider.get().getJobURL(job); client.changeBuildStatus(projectId, commit, BuildState.pending, ref, buildName, targetUrl, BuildState.pending.name()); } catch (WebApplicationException | ProcessingException e) { LOGGER.log(Level.SEVERE, "Failed to set build state to pending", e);