use of com.hp.octane.integrations.dto.snapshots.CIBuildStatus in project octane-gitlab-service by MicroFocus.
the class OctaneServices method getJobBuildStatus.
@Override
public CIBuildStatusInfo getJobBuildStatus(String jobCiId, String parameterName, String parameterValue) {
ParsedPath parsedPath = new ParsedPath(jobCiId, gitLabApi, PathType.PIPELINE);
try {
List<Pipeline> pipelines = gitLabApi.getPipelineApi().getPipelines(parsedPath.getPathWithNameSpace());
Optional<Pipeline> chosenPipeline = pipelines.stream().map(pipeline -> {
try {
List<Variable> pipelineVariables = gitLabApi.getPipelineApi().getPipelineVariables(parsedPath.getPathWithNameSpace(), pipeline.getId());
for (Variable variable : pipelineVariables) {
if (variable.getKey().equals(parameterName) && variable.getValue().equals(parameterValue)) {
return pipeline;
}
}
return null;
} catch (GitLabApiException e) {
log.error("Failed to get variables from pipeline", e);
throw new RuntimeException(e);
}
}).filter(Objects::nonNull).findAny();
if (chosenPipeline.isPresent()) {
String status = chosenPipeline.get().getStatus().toValue();
CIBuildStatus currentCIBuildStatus = getCIBuildStatus(status);
Optional<CIBuildStatus> buildStatus = Arrays.stream(CIBuildStatus.values()).filter(ciBuildStatus -> Objects.equals(ciBuildStatus, currentCIBuildStatus)).findAny();
if (!buildStatus.isPresent()) {
throw new RuntimeException("Failed to get the correct build status");
}
return dtoFactory.newDTO(CIBuildStatusInfo.class).setJobCiId(jobCiId).setBuildStatus(buildStatus.get()).setBuildCiId(getBuildCiId(chosenPipeline.get())).setParamName(parameterName).setParamValue(parameterValue).setResult(getCiBuildResult(status));
}
throw new RuntimeException("Failed to get information about the pipeline");
} catch (GitLabApiException e) {
log.error("Failed to get job build status of the pipeline run", e);
throw new RuntimeException(e);
}
}
Aggregations