|
1 | 1 | /**
|
2 |
| - * Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
| - * contributor license agreements. See the NOTICE file distributed with |
4 |
| - * this work for additional information regarding copyright ownership. |
5 |
| - * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
| - * (the "License"); you may not use this file except in compliance with |
7 |
| - * the License. You may obtain a copy of the License at |
8 |
| - * <p/> |
9 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
10 |
| - * <p/> |
| 2 | + * Copyright (C) 2016 Red Hat, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
11 | 10 | * Unless required by applicable law or agreed to in writing, software
|
12 | 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21 | 20 | import com.squareup.okhttp.Response;
|
22 | 21 | import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
23 | 22 | import hudson.Extension;
|
24 |
| -import hudson.model.Job; |
25 | 23 | import hudson.model.Result;
|
26 | 24 | import hudson.model.Run;
|
27 | 25 | import hudson.model.TaskListener;
|
28 |
| -import hudson.model.TopLevelItem; |
29 | 26 | import hudson.model.listeners.RunListener;
|
30 | 27 | import io.fabric8.kubernetes.api.model.ObjectMeta;
|
31 | 28 | import io.fabric8.openshift.api.model.Build;
|
|
34 | 31 | import io.fabric8.openshift.api.model.BuildConfigSpec;
|
35 | 32 | import io.fabric8.openshift.api.model.BuildList;
|
36 | 33 | import io.fabric8.openshift.api.model.BuildSpec;
|
37 |
| -import io.fabric8.openshift.api.model.BuildStatus; |
38 | 34 | import io.fabric8.openshift.client.OpenShiftClient;
|
39 |
| -import jenkins.model.Jenkins; |
40 | 35 | import jenkins.util.Timer;
|
41 | 36 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
42 | 37 | import org.kohsuke.stapler.DataBoundConstructor;
|
@@ -161,11 +156,7 @@ protected void pollLoop() {
|
161 | 156 | protected void pollRun(String url, Run run) {
|
162 | 157 | BuildName buildName = BuildName.parseBuildUrl(url);
|
163 | 158 |
|
164 |
| - // TODO is there a better place to find this? |
165 |
| - String root = Jenkins.getInstance().getRootUrl(); |
166 |
| - if (root == null || root.length() == 0) { |
167 |
| - root = "http://localhost:8080/jenkins/"; |
168 |
| - } |
| 159 | + String root = JenkinsUtils.getRootUrl(); |
169 | 160 |
|
170 | 161 | String fullUrl = joinPaths(root, url, "/wfapi/describe");
|
171 | 162 | logger.info("Polling URL: " + fullUrl + " for " + buildName);
|
@@ -260,18 +251,18 @@ private void upsertBuild(BuildName buildName, Run run, String json, String url)
|
260 | 251 | phase = BuildPhases.RUNNING;
|
261 | 252 | } else {
|
262 | 253 | Result result = run.getResult();
|
263 |
| - if (result.equals(Result.SUCCESS)) { |
264 |
| - phase = BuildPhases.COMPLETE; |
265 |
| - } else if (result.equals(Result.ABORTED)) { |
266 |
| - phase = BuildPhases.CANCELLED; |
267 |
| - } else if (result.equals(Result.FAILURE)) { |
268 |
| - phase = BuildPhases.FAILED; |
269 |
| - } else if (result.equals(Result.UNSTABLE)) { |
270 |
| - phase = BuildPhases.FAILED; |
271 |
| - } else if (result.equals(Result.NOT_BUILT)) { |
272 |
| - phase = BuildPhases.PENDING; |
273 |
| - } else { |
274 |
| - phase = BuildPhases.PENDING; |
| 254 | + if (result != null) { |
| 255 | + if (result.equals(Result.SUCCESS)) { |
| 256 | + phase = BuildPhases.COMPLETE; |
| 257 | + } else if (result.equals(Result.ABORTED)) { |
| 258 | + phase = BuildPhases.CANCELLED; |
| 259 | + } else if (result.equals(Result.FAILURE)) { |
| 260 | + phase = BuildPhases.FAILED; |
| 261 | + } else if (result.equals(Result.UNSTABLE)) { |
| 262 | + phase = BuildPhases.FAILED; |
| 263 | + } else { |
| 264 | + phase = BuildPhases.PENDING; |
| 265 | + } |
275 | 266 | }
|
276 | 267 | }
|
277 | 268 | }
|
|
0 commit comments