/
RundeckJobProjectLinkerAction.java
70 lines (58 loc) · 2.16 KB
/
RundeckJobProjectLinkerAction.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
package org.jenkinsci.plugins.rundeck;
import hudson.model.Action;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.rundeck.domain.RundeckApiException;
import org.jenkinsci.plugins.rundeck.domain.RundeckInstance;
import org.jenkinsci.plugins.rundeck.domain.RundeckJob;
import org.kohsuke.stapler.export.Exported;
/**
* {@link Action} used to display a RunDeck icon with a link to the RunDeck job page, and some information about the
* RunDeck job, on the Jenkins job page.
*
* @author Vincent Behar
*/
public class RundeckJobProjectLinkerAction implements Action {
private final RundeckInstance rundeck;
private final RundeckJob rundeckJob;
private final String rundeckJobUrl;
/**
* Load the RunDeck job details (name, description, and so on) using the RunDeck API.
*
* @param rundeck instance used for talking to the RunDeck API
* @param rundeckJobId ID of the RunDeck job
* @throws RundeckApiException in case of error while load the job details from RunDeck API
*/
public RundeckJobProjectLinkerAction(RundeckInstance rundeck, String rundeckJobId) throws RundeckApiException {
this.rundeck = rundeck;
this.rundeckJob = rundeck.getJob(rundeckJobId);
this.rundeckJobUrl = buildRundeckJobUrl();
}
/**
* Build the absolute url to the RunDeck job page.
*
* @return the absolute url to the RunDeck job page, or null if unable to build it
*/
private String buildRundeckJobUrl() {
StringBuilder url = new StringBuilder();
url.append(rundeck.getUrl());
if (!StringUtils.endsWith(rundeck.getUrl(), "/")) {
url.append("/");
}
url.append("job/show/");
url.append(rundeckJob.getId());
return url.toString();
}
@Exported
public RundeckJob getRundeckJob() {
return rundeckJob;
}
public String getIconFileName() {
return "/plugin/rundeck/images/rundeck_24x24.png";
}
public String getDisplayName() {
return "RunDeck Job #" + rundeckJob.getId() + " : " + rundeckJob.getName();
}
public String getUrlName() {
return rundeckJobUrl;
}
}