diff --git a/src/main/java/com/microfocus/octane/gitlab/services/GitlabServices.java b/src/main/java/com/microfocus/octane/gitlab/services/GitlabServices.java index 36eff28..f7f7425 100644 --- a/src/main/java/com/microfocus/octane/gitlab/services/GitlabServices.java +++ b/src/main/java/com/microfocus/octane/gitlab/services/GitlabServices.java @@ -127,13 +127,13 @@ private void init() throws MalformedURLException { log.warn("Failed to create GitLab web hooks", e); throw new RuntimeException(e); } - - //start test cleanUp thread - testCleanupExecutor = - Executors.newSingleThreadScheduledExecutor(); - testCleanupScheduledFuture = testCleanupExecutor.scheduleAtFixedRate( - new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()), TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES); - + if(!cleanupOnly) { + //start test cleanUp thread + testCleanupExecutor = Executors.newSingleThreadScheduledExecutor(); + testCleanupScheduledFuture = testCleanupExecutor.scheduleAtFixedRate( + new TestResultsCleanUpRunnable(applicationSettings.getConfig().getTestResultsOutputFolderPath()), + TestResultsCleanUpRunnable.INTERVAL, TestResultsCleanUpRunnable.INTERVAL, TimeUnit.MINUTES); + } } private void initWebHookListenerURL() throws MalformedURLException { @@ -147,16 +147,16 @@ private void initWebHookListenerURL() throws MalformedURLException { @PreDestroy private void stop() { try { + if(!cleanupOnly) { + stopExecutors(); - stopExecutors(); + log.info("Destroying GitLab webhooks ..."); - log.info("Destroying GitLab webhooks ..."); + ProjectFilter filter = new ProjectFilter().withMembership(true).withMinAccessLevel(AccessLevel.MAINTAINER); - ProjectFilter filter = new ProjectFilter().withMembership(true) - .withMinAccessLevel(AccessLevel.MAINTAINER); - - List projects = gitLabApi.getProjectApi().getProjects(filter); - HooksHelper.deleteWebHooks(projects,webhookURL,gitLabApi); + List projects = gitLabApi.getProjectApi().getProjects(filter); + HooksHelper.deleteWebHooks(projects, webhookURL, gitLabApi); + } } catch (Exception e) { log.warn("Failed to destroy GitLab webhooks", e); diff --git a/src/main/java/com/microfocus/octane/gitlab/services/OctaneServices.java b/src/main/java/com/microfocus/octane/gitlab/services/OctaneServices.java index de9e830..d320115 100644 --- a/src/main/java/com/microfocus/octane/gitlab/services/OctaneServices.java +++ b/src/main/java/com/microfocus/octane/gitlab/services/OctaneServices.java @@ -374,12 +374,28 @@ public CIBranchesList getBranchesList(String jobCiId, String filterBranchName) { } + private Optional extractGitLabJob (ParsedPath project, String buildNumber){ + try { + if (project.getPathWithNameSpace().isEmpty()) + throw new RuntimeException("Can not find gitlab project path"); + return Optional.of(gitLabApi.getJobApi().getJob(project.getPathWithNameSpace(), Long.parseLong(buildNumber))); + } catch (GitLabApiException e){ + return Optional.empty(); + } + } + + @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(), Long.parseLong(buildNumber)); + Optional optionalJob = extractGitLabJob(project, buildNumber); + while (optionalJob.isEmpty()){ + project = new ParsedPath(ParsedPath.cutLastPartOfPath(project.getPathWithNameSpace()), gitLabApi, PathType.PROJECT); + optionalJob = extractGitLabJob(project, buildNumber); + } + Job job = optionalJob.get(); //report gherkin test results