|
19 | 19 | */
|
20 | 20 | public class JenkinsTriggerHelper {
|
21 | 21 |
|
22 |
| - private JenkinsServer server; |
| 22 | + private final JenkinsServer server; |
| 23 | + private final Long retryInterval; |
| 24 | + private static final Long DEFAULT_RETRY_INTERVAL = 200L; |
23 | 25 |
|
24 | 26 | public JenkinsTriggerHelper(JenkinsServer server) {
|
25 | 27 | this.server = server;
|
| 28 | + this.retryInterval = DEFAULT_RETRY_INTERVAL; |
| 29 | + } |
| 30 | + |
| 31 | + public JenkinsTriggerHelper(JenkinsServer server, Long retryInterval) { |
| 32 | + this.server = server; |
| 33 | + this.retryInterval = retryInterval; |
26 | 34 | }
|
27 | 35 |
|
28 | 36 | /**
|
@@ -114,37 +122,26 @@ public BuildWithDetails triggerJobAndWaitUntilFinished(String jobName, boolean c
|
114 | 122 | */
|
115 | 123 | private BuildWithDetails triggerJobAndWaitUntilFinished(String jobName, QueueReference queueRef)
|
116 | 124 | throws IOException, InterruptedException {
|
117 |
| - JobWithDetails job; |
118 |
| - job = this.server.getJob(jobName); |
| 125 | + JobWithDetails job = this.server.getJob(jobName); |
119 | 126 | QueueItem queueItem = this.server.getQueueItem(queueRef);
|
| 127 | + |
120 | 128 | while (!queueItem.isCancelled() && job.isInQueue()) {
|
121 |
| - // TODO: May be we should make this configurable? |
122 |
| - Thread.sleep(200); |
| 129 | + Thread.sleep(retryInterval); |
123 | 130 | job = this.server.getJob(jobName);
|
124 | 131 | queueItem = this.server.getQueueItem(queueRef);
|
125 | 132 | }
|
126 | 133 |
|
| 134 | + Build build = server.getBuild(queueItem); |
127 | 135 | if (queueItem.isCancelled()) {
|
128 |
| - // TODO: Check if this is ok? |
129 |
| - // We will get the details of the last build. NOT of the cancelled |
130 |
| - // build, cause there is no information about that available cause |
131 |
| - // it does not exist. |
132 |
| - BuildWithDetails result = new BuildWithDetails(job.getLastBuild().details()); |
133 |
| - // TODO: Should we add more information here? |
134 |
| - result.setResult(BuildResult.CANCELLED); |
135 |
| - return result; |
| 136 | + return build.details(); |
136 | 137 | }
|
137 | 138 |
|
138 |
| - job = this.server.getJob(jobName); |
139 |
| - Build lastBuild = job.getLastBuild(); |
140 |
| - |
141 |
| - boolean isBuilding = lastBuild.details().isBuilding(); |
| 139 | + boolean isBuilding = build.details().isBuilding(); |
142 | 140 | while (isBuilding) {
|
143 |
| - // TODO: May be we should make this configurable? |
144 |
| - Thread.sleep(200); |
145 |
| - isBuilding = lastBuild.details().isBuilding(); |
| 141 | + Thread.sleep(retryInterval); |
| 142 | + isBuilding = build.details().isBuilding(); |
146 | 143 | }
|
147 | 144 |
|
148 |
| - return lastBuild.details(); |
| 145 | + return build.details(); |
149 | 146 | }
|
150 | 147 | }
|
0 commit comments