use of org.gitlab4j.api.models.Pipeline 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);
}
}
use of org.gitlab4j.api.models.Pipeline in project choerodon-starters by open-hand.
the class PipelineApi method createPipeline.
/**
* Create a pipelines in a project.
* <p>
* POST /projects/:id/pipelines
*
* @param projectId the project ID to create a pipeline in
* @param ref reference to commit
* @return a Pipeline instance with the newly created pipeline info
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline createPipeline(int projectId, String ref) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("ref", ref);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "pipeline");
return (response.readEntity(Pipeline.class));
}
Aggregations