Skip to content

Commit

Permalink
Merge pull request #4 from jenkinsci/FailedToFindJob
Browse files Browse the repository at this point in the history
Fixed Bug with error handling of unreachable jobs
  • Loading branch information
aberkIBM authored May 2, 2018
2 parents cdcb53f + e1581ed commit 9a19661
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
15 changes: 6 additions & 9 deletions src/main/java/com/ibm/devops/connect/CloudWorkListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public void callSecured(ConnectSocket socket, String event, Object... args) {
JSONArray incomingJobs = JSONArray.fromObject(args[0].toString());

for(int i=0; i < incomingJobs.size(); i++) {

WorkStatus workStatus = WorkStatus.started;

JSONObject incomingJob = incomingJobs.getJSONObject(i);
// sample job creation request from a toolchain
if (incomingJob.has("jobType") && "new".equalsIgnoreCase(incomingJob.get("jobType").toString())) {
Expand Down Expand Up @@ -151,9 +154,6 @@ public void callSecured(ConnectSocket socket, String event, Object... args) {
} else if (item instanceof WorkflowJob) {
WorkflowJob workflowJob = (WorkflowJob)item;

System.out.println("\n\n\t\t\t&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
System.out.println(parametersList);

QueueTaskFuture queuedTask = workflowJob.scheduleBuild2(0, new ParametersAction(parametersList), new CauseAction(cloudCause));

if (queuedTask == null) {
Expand All @@ -172,11 +172,13 @@ public void callSecured(ConnectSocket socket, String event, Object... args) {
JSONObject statusUpdate = erroredJobStatus.generateErrorStatus(errorMessage);
CloudPublisher cloudPublisher = new CloudPublisher();
cloudPublisher.uploadJobStatus(statusUpdate);

workStatus = WorkStatus.failed;
}

}

sendResult(socket, incomingJobs.getJSONObject(i).get("id").toString(), WorkStatus.started, "This work has been started");
sendResult(socket, incomingJobs.getJSONObject(i).get("id").toString(), workStatus, "This work has been started");
}

}
Expand All @@ -197,11 +199,6 @@ private void sendResult(ConnectSocket socket, String id, WorkStatus status, Stri
private List<ParameterValue> generateParamList (JSONObject incomingJob, Map<String, String> typeMap) {
ArrayList<ParameterValue> result = new ArrayList<ParameterValue>();

System.out.println("000000000000000000000000000000000");
System.out.println(incomingJob.toString());
System.out.println(typeMap.toString());
System.out.println("000000000000000000000000000000000");

if(incomingJob.has("props")) {
JSONObject props = incomingJob.getJSONObject("props");
Iterator<String> keys = props.keys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ abstract class AbstractJenkinsStatus {
protected Boolean isPaused;

protected void getOrCreateCrAction() {
// Get CrAction
List<Action> actions = run.getActions();
for(Action action : actions) {
if (action instanceof CrAction) {
crAction = (CrAction)action;
if (run != null) {
// Get CrAction
List<Action> actions = run.getActions();
for(Action action : actions) {
if (action instanceof CrAction) {
crAction = (CrAction)action;
}
}
}

// If not, create crAction
if (crAction == null) {
crAction = new CrAction();
run.addAction(crAction);
// If not, create crAction
if (crAction == null) {
crAction = new CrAction();
run.addAction(crAction);
}
}
}

Expand Down

0 comments on commit 9a19661

Please sign in to comment.