-
Notifications
You must be signed in to change notification settings - Fork 16
/
BlueOceanDisplayURLImpl.java
73 lines (62 loc) · 2.27 KB
/
BlueOceanDisplayURLImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.jenkinsci.plugins.blueoceandisplayurl;
import hudson.Extension;
import hudson.Util;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.model.Jenkins;
import hudson.tasks.test.TestResult;
import jenkins.branch.MultiBranchProject;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
/**
*`@author Ivan Meredith
*/
@Extension
public class BlueOceanDisplayURLImpl extends DisplayURLProvider {
@Override
public String getRoot() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new IllegalStateException("Jenkins has not started");
}
String root = jenkins.getRootUrl();
if (root == null) {
root = "http://unconfigured-jenkins-location/";
}
return root + "blue/";
}
@Override
public String getRunURL(Run<?, ?> run) {
if(run instanceof WorkflowRun) {
WorkflowJob job = ((WorkflowRun) run).getParent();
if(job.getParent() instanceof MultiBranchProject) {
return getJobURL(((MultiBranchProject) job.getParent()))+ "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
}
}
Job job = run.getParent();
return getJobURL(job) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
}
@Override
public String getChangesURL(Run<?, ?> run) {
return getRunURL(run) + "changes";
}
public String getJobURL(MultiBranchProject<?, ?> project) {
String jobPath = Util.rawEncode(project.getFullName());
return getRoot() + "organizations/jenkins/" + jobPath + "/";
}
@Override
public String getJobURL(Job<?, ?> project) {
String jobPath;
if(project.getParent() instanceof MultiBranchProject) {
jobPath = Util.rawEncode(project.getParent().getFullName());
} else {
jobPath = Util.rawEncode(project.getFullName());
}
return getRoot() + "organizations/jenkins/" + jobPath + "/";
}
@Override
public String getTestUrl(TestResult result) {
return getRunURL(result.getRun()) + "/tests";
}
}