|
21 | 21 | package com.microfocus.application.automation.tools.octane.model.processors.projects; |
22 | 22 |
|
23 | 23 | import com.hp.octane.integrations.dto.pipelines.PipelinePhase; |
24 | | -import com.microfocus.application.automation.tools.octane.model.processors.builders.*; |
| 24 | +import com.microfocus.application.automation.tools.octane.executor.UftConstants; |
| 25 | +import com.microfocus.application.automation.tools.octane.model.processors.builders.AbstractBuilderProcessor; |
| 26 | +import com.microfocus.application.automation.tools.octane.model.processors.builders.BuildTriggerProcessor; |
| 27 | +import com.microfocus.application.automation.tools.octane.model.processors.builders.ParameterizedTriggerProcessor; |
25 | 28 | import com.microfocus.application.automation.tools.octane.tests.build.BuildHandlerUtils; |
26 | 29 | import hudson.model.*; |
27 | 30 | import hudson.tasks.Builder; |
28 | 31 | import hudson.tasks.Publisher; |
| 32 | +import jenkins.model.Jenkins; |
29 | 33 | import org.apache.logging.log4j.LogManager; |
30 | 34 | import org.apache.logging.log4j.Logger; |
31 | 35 |
|
@@ -76,28 +80,51 @@ public void scheduleBuild(Cause cause, ParametersAction parametersAction) { |
76 | 80 | } |
77 | 81 |
|
78 | 82 | public void cancelBuild(Cause cause, ParametersAction parametersAction) { |
| 83 | + String suiteId = (String) parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue(); |
| 84 | + String suiteRunId = (String) parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue(); |
| 85 | + logger.info("cancelBuild for suiteId=" + suiteId +", suiteRunId=" + suiteRunId); |
79 | 86 | if (job instanceof AbstractProject) { |
80 | 87 | AbstractProject project = (AbstractProject) job; |
| 88 | + Queue queue = Jenkins.get().getQueue(); |
| 89 | + queue.getItems(project).forEach(item -> { |
| 90 | + item.getActions(ParametersAction.class).forEach(action -> { |
| 91 | + if (checkSuiteIdParamsExistAndEqual(action, suiteId, suiteRunId)) { |
| 92 | + try { |
| 93 | + logger.info("canceling item in queue : " + item.getDisplayName()); |
| 94 | + queue.cancel(item); |
| 95 | + } catch (Exception e) { |
| 96 | + logger.warn("Failed to cancel '" + item.getDisplayName() + "' in queue : " + e.getMessage(), e); |
| 97 | + } |
| 98 | + } |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
81 | 102 | project.getBuilds().forEach(build -> { |
82 | 103 | if (build instanceof AbstractBuild) { |
83 | | - AbstractBuild abuild = (AbstractBuild) build; |
84 | | - abuild.getActions(ParametersAction.class).forEach(action -> { |
85 | | - if (action.getParameter("suiteId").getValue().equals(parametersAction.getParameter("suiteId").getValue()) |
86 | | - && action.getParameter("suiteRunId").getValue().equals(parametersAction.getParameter("suiteRunId").getValue())) { |
| 104 | + AbstractBuild aBuild = (AbstractBuild) build; |
| 105 | + aBuild.getActions(ParametersAction.class).forEach(action -> { |
| 106 | + if (checkSuiteIdParamsExistAndEqual(action, suiteId, suiteRunId)) { |
87 | 107 | try { |
88 | | - abuild.doStop(); |
| 108 | + aBuild.doStop(); |
89 | 109 | } catch (Exception e) { |
90 | | - logger.warn(e); |
| 110 | + logger.warn("Failed to stop build '" + aBuild.getDisplayName() + "' :" + e.getMessage(), e); |
91 | 111 | } |
92 | 112 | } |
93 | 113 | }); |
94 | 114 | } |
95 | 115 | }); |
96 | 116 | } else { |
97 | | - throw new IllegalStateException("unsupported job CAN NOT be stop"); |
| 117 | + throw new IllegalStateException("unsupported job CAN NOT be stopped"); |
98 | 118 | } |
99 | 119 | } |
100 | 120 |
|
| 121 | + private boolean checkSuiteIdParamsExistAndEqual(ParametersAction parametersAction, String suiteId, String suiteRunId) { |
| 122 | + ParameterValue suiteIdPV = parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME); |
| 123 | + ParameterValue suiteRunIdPV = parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME); |
| 124 | + return (suiteIdPV != null && suiteRunIdPV != null && suiteIdPV.getValue().equals(suiteId) |
| 125 | + && suiteRunIdPV.getValue().equals(suiteRunId)); |
| 126 | + } |
| 127 | + |
101 | 128 | /** |
102 | 129 | * Retrieve Job's CI ID |
103 | 130 | * return the job name, in case of a folder job, this method returns the refactored |
|
0 commit comments