use of org.gitlab4j.api.models.Job in project octane-gitlab-service by MicroFocus.
the class OctaneServices method getTestsResult.
@Override
public InputStream getTestsResult(String jobFullName, String buildNumber) {
TestsResult result = dtoFactory.newDTO(TestsResult.class);
try {
ParsedPath project = new ParsedPath(ParsedPath.cutLastPartOfPath(jobFullName), gitLabApi, PathType.PROJECT);
Job job = gitLabApi.getJobApi().getJob(project.getPathWithNameSpace(), Integer.parseInt(buildNumber));
// report gherkin test results
File mqmTestResultsFile = TestResultsHelper.getMQMTestResultsFilePath(project.getId(), job.getId(), applicationSettings.getConfig().getTestResultsOutputFolderPath());
InputStream output = null;
if (mqmTestResultsFile.exists() && mqmTestResultsFile.length() > 0) {
log.info(String.format("get Gherkin Tests Result of %s from %s, file exist=%s", project.getDisplayName(), mqmTestResultsFile.getAbsolutePath(), mqmTestResultsFile.exists()));
try {
output = mqmTestResultsFile.exists() && mqmTestResultsFile.length() > 0 ? new FileInputStream(mqmTestResultsFile.getAbsolutePath()) : null;
} catch (IOException e) {
log.error("failed to get gherkin test results for " + project.getDisplayName() + " #" + job.getId() + " from " + mqmTestResultsFile.getAbsolutePath());
}
return output;
}
// if there is no test results for gherkin - report other test results
BuildContext buildContext = dtoFactory.newDTO(BuildContext.class).setJobId(project.getFullPathOfProjectWithBranch().toLowerCase()).setJobName(project.getPathWithNameSpace()).setBuildId(job.getId().toString()).setBuildName(job.getId().toString()).setServerId(applicationSettings.getConfig().getCiServerIdentity());
result = result.setBuildContext(buildContext);
JunitTestResultsProvider junitTestResultsProvider = JunitTestResultsProvider.getInstance(applicationSettings);
InputStream artifactFiles = gitLabApi.getJobApi().downloadArtifactsFile(project.getId(), job.getId());
List<TestRun> tests = junitTestResultsProvider.createAndGetTestList(artifactFiles);
if (tests != null && !tests.isEmpty()) {
result.setTestRuns(tests);
} else {
log.warn("Unable to extract test results from files defined by the %s pattern. Check the pattern correctness");
}
} catch (Exception e) {
log.warn("Failed to return test results", e);
}
return dtoFactory.dtoToXmlStream(result);
}
use of org.gitlab4j.api.models.Job in project choerodon-starters by open-hand.
the class JobApi method getJobs.
/**
* Get a list of jobs in a project.
* <p>
* GET /projects/:id/jobs
*
* @param projectId the project ID to get the list of jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @return a list containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Job> getJobs(int projectId, JobScope scope) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Status.OK, formData.asMap(), "projects", projectId, "jobs");
return (response.readEntity(new GenericType<List<Job>>() {
}));
}
use of org.gitlab4j.api.models.Job in project choerodon-starters by open-hand.
the class JobApi method eraseJob.
/**
* Erase specified job in a project.
* <p>
* POST /projects/:id/jobs/:job_id/erase
*
* @param projectId the project ID to erase specified job
* @param jobId the ID to erase job
* @return job instance which just erased
* @throws GitLabApiException if any exception occurs during execution
*/
public Job eraseJob(int projectId, int jobId) throws GitLabApiException {
GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", projectId, "jobs", jobId, "erase");
return (response.readEntity(Job.class));
}
use of org.gitlab4j.api.models.Job 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.Job in project choerodon-starters by open-hand.
the class JobApi method getJobsForPipeline.
/**
* Get a list of jobs in a pipeline.
* <p>
* GET /projects/:id/pipelines/:pipeline_id/jobs
*
* @param projectId the project ID to get the list of pipeline for
* @param pipelineId the pipeline ID to get the list of jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @return a list containing the jobs for the specified project ID and pipeline ID
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Job> getJobsForPipeline(int projectId, int pipelineId, JobScope scope) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Status.OK, formData.asMap(), "projects", projectId, "pipelines", pipelineId, "jobs");
return (response.readEntity(new GenericType<List<Job>>() {
}));
}
Aggregations