Removed the build number from target url when the state is pending
(job is waiting for the next available executor). Build number in the url causes problems when there are more than one job in the build queue. In those cases job.getNextBuildNumber returns the same number for every build in the queue which leads to wrong urls reported to Gitlab. The build number is assigned when the execution starts so the best option for pending builds is probably just to set the target url point to the job page without the build number.
This commit is contained in:
parent
df7432a760
commit
4ecec17236
|
@ -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<H extends WebHook> 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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue