-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-72059] Add new quality gate options to alter the stage only.
- Loading branch information
Showing
11 changed files
with
207 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/io/jenkins/plugins/util/QualityGateNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.jenkins.plugins.util; | ||
|
||
/** | ||
* Notifies the build or stage about the quality gate result. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public interface QualityGateNotifier { | ||
/** | ||
* Called to notify the build or stage about the quality gate status. | ||
* | ||
* @param status | ||
* the quality gate status | ||
* @param message | ||
* a message that describes the cause for the result | ||
*/ | ||
void publishResult(QualityGateStatus status, String message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/io/jenkins/plugins/util/PipelineResultHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.jenkins.plugins.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.Issue; | ||
|
||
import org.jenkinsci.plugins.workflow.actions.WarningAction; | ||
import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
import hudson.model.Action; | ||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class PipelineResultHandlerTest { | ||
private static final String MESSAGE = "message"; | ||
|
||
@Test | ||
void shouldSetRunResult() { | ||
var run = mock(Run.class); | ||
var flowNode = mock(FlowNode.class); | ||
|
||
var handler = new PipelineResultHandler(run, flowNode); | ||
handler.publishResult(QualityGateStatus.PASSED, MESSAGE); | ||
|
||
verifyNoInteractions(run); | ||
verifyNoInteractions(flowNode); | ||
|
||
handler.publishResult(QualityGateStatus.WARNING, MESSAGE); | ||
Check warning on line 28 in src/test/java/io/jenkins/plugins/util/PipelineResultHandlerTest.java ci.jenkins.io / CPDCPD
Raw output
|
||
verify(run).setResult(Result.UNSTABLE); | ||
verify(flowNode).addOrReplaceAction(argThat(action -> hasFlowNode(action, Result.UNSTABLE))); | ||
|
||
handler.publishResult(QualityGateStatus.FAILED, MESSAGE); | ||
verify(run).setResult(Result.FAILURE); | ||
verify(flowNode).addOrReplaceAction(argThat(action -> hasFlowNode(action, Result.FAILURE))); | ||
} | ||
|
||
@Test @Issue("JENKINS-72059") | ||
void shouldSetStageResult() { | ||
var run = mock(Run.class); | ||
var flowNode = mock(FlowNode.class); | ||
|
||
var handler = new PipelineResultHandler(run, flowNode); | ||
handler.publishResult(QualityGateStatus.PASSED, MESSAGE); | ||
|
||
verifyNoInteractions(run); | ||
verifyNoInteractions(flowNode); | ||
|
||
handler.publishResult(QualityGateStatus.NOTE, MESSAGE); | ||
Check warning on line 48 in src/test/java/io/jenkins/plugins/util/PipelineResultHandlerTest.java ci.jenkins.io / CPDCPD
Raw output
|
||
verifyNoInteractions(run); | ||
verify(flowNode).addOrReplaceAction(argThat(action -> hasFlowNode(action, Result.UNSTABLE))); | ||
|
||
handler.publishResult(QualityGateStatus.ERROR, MESSAGE); | ||
verifyNoInteractions(run); | ||
verify(flowNode).addOrReplaceAction(argThat(action -> hasFlowNode(action, Result.FAILURE))); | ||
} | ||
|
||
private boolean hasFlowNode(final Action action, final Result result) { | ||
if (!(action instanceof WarningAction)) { | ||
return false; | ||
} | ||
WarningAction warningAction = (WarningAction) action; | ||
return result.equals(warningAction.getResult()) && MESSAGE.equals(warningAction.getMessage()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/io/jenkins/plugins/util/RunResultHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.jenkins.plugins.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class RunResultHandlerTest { | ||
Check notice Code scanning / CodeQL Unused classes and interfaces Note test
Unused class: RunResultHandlerTest is not referenced within this codebase. If not used as an external API it should be removed.
|
||
private static final String MESSAGE = "message"; | ||
|
||
@Test | ||
void shouldSetRunResult() { | ||
var run = mock(Run.class); | ||
|
||
var handler = new RunResultHandler(run); | ||
handler.publishResult(QualityGateStatus.PASSED, MESSAGE); | ||
|
||
verifyNoInteractions(run); | ||
|
||
handler.publishResult(QualityGateStatus.WARNING, MESSAGE); | ||
verify(run).setResult(Result.UNSTABLE); | ||
|
||
handler.publishResult(QualityGateStatus.FAILED, MESSAGE); | ||
verify(run).setResult(Result.FAILURE); | ||
} | ||
} |