use of com.hp.octane.integrations.dto.parameters.CIParameter in project octane-ci-java-sdk by MicroFocus.
the class TasksProcessorImpl method executePipelineRunExecuteRequest.
private void executePipelineRunExecuteRequest(OctaneResultAbridged result, String jobId, String originalBody) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "RunExecute job " + jobId);
// test runner started from here, so it will be added to cache
configurationService.addToOctaneRootsCache(jobId);
CIParameters ciParameters = originalBody != null ? DTOFactory.getInstance().dtoFromJson(originalBody, CIParameters.class) : null;
if (ciParameters == null) {
ciParameters = dtoFactory.newDTO(CIParameters.class);
ciParameters.setParameters(new ArrayList<>());
}
CIParameter ciParameter = dtoFactory.newDTO(CIParameter.class);
ciParameter.setName(SdkConstants.JobParameters.OCTANE_CONFIG_ID_PARAMETER_NAME).setValue(configurer.octaneConfiguration.getInstanceId());
ciParameters.getParameters().add(ciParameter);
CIParameter octaneUrlParameter = dtoFactory.newDTO(CIParameter.class);
octaneUrlParameter.setName(SdkConstants.JobParameters.OCTANE_URL_PARAMETER_NAME).setValue(configurer.octaneConfiguration.getUrl());
ciParameters.getParameters().add(octaneUrlParameter);
configurer.pluginServices.runPipeline(jobId, ciParameters);
result.setStatus(HttpStatus.SC_CREATED);
}
use of com.hp.octane.integrations.dto.parameters.CIParameter in project octane-ci-java-sdk by MicroFocus.
the class TaskingServiceTests method testJobsWithParamsAPI.
@Test
public void testJobsWithParamsAPI() {
TasksProcessor tasksProcessor = client.getTasksProcessor();
Assert.assertNotNull(tasksProcessor);
OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs");
OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
runCommonAsserts(resultAbridged, taskAbridged.getId(), HttpStatus.SC_OK);
CIJobsList ciJobsList = dtoFactory.dtoFromJson(resultAbridged.getBody(), CIJobsList.class);
Assert.assertNotNull(ciJobsList);
Assert.assertNotNull(ciJobsList.getJobs());
Assert.assertEquals(3, ciJobsList.getJobs().length);
for (PipelineNode ciJob : ciJobsList.getJobs()) {
Assert.assertNotNull(ciJob);
Assert.assertTrue(ciJob.getName().startsWith("Job "));
Assert.assertTrue(ciJob.getJobCiId().startsWith("job-"));
Assert.assertNotNull(ciJob.getParameters());
Assert.assertEquals(3, ciJob.getParameters().size());
for (CIParameter ciParameter : ciJob.getParameters()) {
Assert.assertNotNull(ciParameter);
Assert.assertNotNull(ciParameter.getName());
Assert.assertNotNull(ciParameter.getType());
Assert.assertNotNull(ciParameter.getValue());
}
}
}
use of com.hp.octane.integrations.dto.parameters.CIParameter in project octane-gitlab-service by MicroFocus.
the class GitlabServices method getParameters.
public List<CIParameter> getParameters(ParsedPath project) {
List<CIParameter> parametersList = new ArrayList<>();
List<Variable> projectVariables = VariablesHelper.getVariables(project, gitLabApi, applicationSettings.getConfig());
projectVariables.forEach(var -> {
CIParameter param = dtoFactory.newDTO(CIParameter.class);
param.setType(CIParameterType.STRING);
param.setName(var.getKey());
param.setDefaultValue(var.getValue());
parametersList.add(param);
});
return parametersList;
}
use of com.hp.octane.integrations.dto.parameters.CIParameter in project octane-gitlab-service by MicroFocus.
the class EventListener method handleEvent.
private Response handleEvent(JSONObject event) {
log.traceEntry();
try {
if (isMergeRequestEvent(event)) {
return handleMergeRequestEvent(event);
}
CIEventType eventType = getEventType(event);
if (eventType == CIEventType.UNDEFINED || eventType == CIEventType.QUEUED)
return Response.ok().build();
List<CIEvent> eventList = getCIEvents(event);
eventList.forEach(ciEvent -> {
if (ciEvent.getResult() == null) {
ciEvent.setResult(CIBuildResult.UNAVAILABLE);
}
try {
log.trace(new ObjectMapper().writeValueAsString(ciEvent));
} catch (Exception e) {
log.debug("Failed to trace an incoming event", e);
}
if (eventType == CIEventType.FINISHED || eventType == CIEventType.STARTED) {
ParsedPath parsedPath = null;
if (ciEvent.getProject().endsWith("/build")) {
parsedPath = new ParsedPath(ciEvent.getProject().substring(0, ciEvent.getProject().length() - 6), gitLabApi, PathType.PROJECT);
if (parsedPath.isMultiBranch()) {
ciEvent.setSkipValidation(true);
}
}
if (ciEvent.getProject().contains(ParsedPath.PIPELINE_JOB_CI_ID_PREFIX)) {
parsedPath = new ParsedPath(ciEvent.getProject(), gitLabApi, PathType.PIPELINE);
if (parsedPath.isMultiBranch()) {
String projectDisplayName = parsedPath.getNameWithNameSpaceForDisplayName() != null ? parsedPath.getNameWithNameSpaceForDisplayName() : parsedPath.getFullPathOfProjectWithBranch();
ciEvent.setProjectDisplayName(projectDisplayName + "/" + parsedPath.getCurrentBranch());
ciEvent.setParentCiId(parsedPath.getJobCiId(true)).setMultiBranchType(MultiBranchType.MULTI_BRANCH_CHILD).setSkipValidation(true);
}
}
if (isPipelineEvent(event)) {
List<CIParameter> parametersList = new ArrayList<>();
JSONArray variablesList = VariablesHelper.getVariablesListFromPipelineEvent(event);
// check if this parameter is in job level:
List<Variable> allVariables = VariablesHelper.getVariables(parsedPath, gitLabApi, applicationSettings.getConfig());
variablesList.forEach(var -> {
parametersList.add(VariablesHelper.convertVariableToParameter(var));
});
if (parametersList.size() > 0) {
ciEvent.setParameters(parametersList);
}
}
}
OctaneSDK.getClients().forEach(client -> client.getEventsService().publishEvent(ciEvent));
});
if (eventType == CIEventType.FINISHED) {
Integer projectId = isPipelineEvent(event) ? event.getJSONObject("project").getInt("id") : event.getInt("project_id");
if (!isPipelineEvent(event)) {
Project project = gitLabApi.getProjectApi().getProject(projectId);
Integer jobId = getEventTargetObjectId(event);
Job job = gitLabApi.getJobApi().getJob(projectId, jobId);
if (job.getArtifactsFile() != null) {
sendCodeCoverage(projectId, project, job);
GherkinTestResultsProvider gherkinTestResultsProvider = GherkinTestResultsProvider.getInstance(applicationSettings);
boolean isGherkinTestsExist = gherkinTestResultsProvider.createTestList(project, job, gitLabApi.getJobApi().downloadArtifactsFile(projectId, job.getId()));
// looking for Regular tests
if (!isGherkinTestsExist) {
JunitTestResultsProvider testResultsProduce = JunitTestResultsProvider.getInstance(applicationSettings);
boolean testResultsExist = testResultsProduce.createTestList(project, job, gitLabApi.getJobApi().downloadArtifactsFile(projectId, job.getId()));
if (!testResultsExist) {
String warning = String.format("No test results found by using the %s pattern", applicationSettings.getConfig().getGitlabTestResultsFilePattern());
log.warn(warning);
return Response.ok().entity(warning).build();
}
}
}
}
}
} catch (Exception e) {
log.warn("An error occurred while handling GitLab event", e);
}
log.traceExit();
return Response.ok().build();
}
use of com.hp.octane.integrations.dto.parameters.CIParameter in project octane-gitlab-service by MicroFocus.
the class VariablesHelper method convertVariableToParameter.
public static CIParameter convertVariableToParameter(Object var) {
String key = (String) ((JSONObject) var).get(KEY);
String value = (String) ((JSONObject) var).get(VALUE);
CIParameter param = dtoFactory.newDTO(CIParameter.class);
param.setType(CIParameterType.STRING);
param.setName(key);
param.setValue(value);
return param;
}
Aggregations