private List stageHistoryAsJson(PipelineInstanceModel pipelineInstanceModel, StageInstanceModels stageHistory) { List json = new ArrayList(); for (StageInstanceModel stageHistoryItem : stageHistory) { Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put("stageName", stageHistoryItem.getName()); jsonMap.put("stageId", stageHistoryItem.getId()); jsonMap.put("stageStatus", stageHistoryItem.getState().toString()); StageIdentifier stageIdentifier = new StageIdentifier(pipelineInstanceModel.getPipelineIdentifier(), stageHistoryItem.getName(), stageHistoryItem.getCounter()); jsonMap.put("stageLocator", encodeInUtf8(stageIdentifier.stageLocator())); jsonMap.put("getCanRun", Boolean.toString(stageHistoryItem.getCanRun())); jsonMap.put("getCanCancel", Boolean.toString(stageHistoryItem.getCanCancel())); jsonMap.put("scheduled", Boolean.toString(stageHistoryItem.isScheduled())); jsonMap.put("stageCounter", stageHistoryItem.getCounter()); handleApproval(stageHistoryItem, jsonMap); json.add(jsonMap); } return json; }
for (JobHistoryItem job : runningStage.getBuildHistory()) { String stageName = runningStage.getName(); String stageCounter = runningStage.getCounter(); if (job.isRunning()) { JobIdentifier jobIdentifier = new JobIdentifier(pipelineName, pipelineCounter, pipelineLabel, stageName, stageCounter, job.getName());
public static void toJSON(OutputWriter jsonOutputWriter, StageInstanceModel model, String pipelineName, String pipelineCounter) { jsonOutputWriter .addLinks(linkWriter -> { linkWriter.addLink("self", Routes.Stage.self(pipelineName, pipelineCounter, model.getName(), model.getCounter())); }) .add("name", model.getName()) .add("counter", model.getCounter()) .add("status", model.getState().name()) .add("approved_by", model.getApprovedBy()) .add("scheduled_at", model.getScheduledDate()); if (model.getPreviousStage() != null) { jsonOutputWriter.addChild("previous_stage", childWriter -> { StageRepresenter.toJSON(childWriter, model.getPreviousStage(), pipelineName, pipelineCounter); }); } } }
public static void toJSON(OutputWriter jsonOutputWriter, StageInstanceModel model, String pipelineName, String pipelineCounter) { jsonOutputWriter .addLinks(linkWriter -> { linkWriter.addLink("self", Routes.Stage.self(pipelineName, pipelineCounter, model.getName(), model.getCounter())); }) .add("name", model.getName()) .add("counter", model.getCounter()) .add("status", model.getState().name()) .add("approved_by", model.getApprovedBy()) .add("scheduled_at", model.getScheduledDate()); if (model.getState().stageResult() == StageResult.Cancelled) { jsonOutputWriter.add("cancelled_by", model.getCancelledBy() == null ? "GoCD" : model.getCancelledBy()); } if (model.getPreviousStage() != null) { jsonOutputWriter.addChild("previous_stage", childWriter -> { StageRepresenter.toJSON(childWriter, model.getPreviousStage(), pipelineName, pipelineCounter); }); } } }