Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,153 +145,4 @@ public void testBlockStage() throws Exception {
assertChunkBoundary(stages.get(2), 15, 16, 20, 21);
}

/** Should find dangling mixes of stages */
@Test
public void mixedStageScoping() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Nasty edge-case finding job");
job.setDefinition(new CpsFlowDefinition("" +
"echo 'stuff'\n" +
"stage 'first'\n" +
"echo 'ran first'\n" +
"stage ('second') {\n" +
" echo 'ran second'\n" +
"}\n" +
"echo 'orphan step'\n" +
"stage 'third'\n" +
"echo 'ran third'\n" +
"stage ('fourth') {\n" +
" echo 'ran fourth'\n" +
"}\n" +
"echo 'another orphan step'",
true));
WorkflowRun build = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

/*
* Node dump follows, format:
[ID]{parent,ids}(millisSinceStartOfRun) flowNodeClassName stepDisplayName [st=startId if a block node]
Action format:
- actionClassName actionDisplayName
------------------------------------------------------------------------------------------
[2]{}FlowStartNode Start of Pipeline
[3]{2}StepAtomNode Print Message
-LogActionImpl Console Output
[4]{3}StepAtomNode first
-LogActionImpl Console Output
-LabelAction first
-StageActionImpl null
[5]{4}StepAtomNode Print Message
-LogActionImpl Console Output
[6]{5}StepStartNode Stage : Start
[7]{6}StepStartNode second
-BodyInvocationAction null
-LabelAction second
[8]{7}StepAtomNode Print Message
-LogActionImpl Console Output
[9]{8}StepEndNode Stage : Body : End [st=7]
-BodyInvocationAction null
[10]{9}StepEndNode Stage : End [st=6]
[11]{10}StepAtomNode Print Message
-LogActionImpl Console Output
[12]{11}StepAtomNode third
-LogActionImpl Console Output
-LabelAction third
-StageActionImpl null
[13]{12}StepAtomNode Print Message
-LogActionImpl Console Output
[14]{13}StepStartNode Stage : Start
[15]{14}StepStartNode fourth
-BodyInvocationAction null
-LabelAction fourth
[16]{15}StepAtomNode Print Message
-LogActionImpl Console Output
[17]{16}StepEndNode Stage : Body : End [st=15]
-BodyInvocationAction null
[18]{17}StepEndNode Stage : End [st=14]
[19]{18}StepAtomNode Print Message
-LogActionImpl Console Output
[20]{19}FlowEndNode End of Pipeline [st=2]
*/

ForkScanner scan = new ForkScanner();
scan.setup(build.getExecution().getCurrentHeads());
CollectingChunkVisitor visitor = new CollectingChunkVisitor();
scan.visitSimpleChunks(visitor, new StageChunkFinder());
List<MemoryFlowChunk> stages = visitor.getChunks();

Assert.assertEquals(4, stages.size());
assertChunkBoundary(stages.get(0), 3, 4, 6, 7);
assertChunkBoundary(stages.get(1), 6, 7, 9, 10);
assertChunkBoundary(stages.get(2), 11, 12, 14, 15);
assertChunkBoundary(stages.get(3), 14, 15, 17, 18);
}

/** Single-step stage markers */
@Test
public void testLegacyStage() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Legacy stage job");

job.setDefinition(new CpsFlowDefinition("" +
"node {" +
" stage ('Build'); " +
" echo ('Building'); " +
" stage ('Test'); " +
" echo ('Testing'); " +
" stage ('Deploy'); " +
" writeFile file: 'file.txt', text:'content'; " +
" archive(includes: 'file.txt'); " +
" echo ('Deploying'); " +
"}", true));
/*
* Node dump follows, format:
[ID]{parent,ids} flowNodeClassName stepDisplayName [st=startId if a block node]
Action format:
- actionClassName actionDisplayName
------------------------------------------------------------------------------------------
[2]{}FlowStartNode Start of Pipeline
[3]{2}StepStartNode Allocate node : Start
-LogActionImpl Console Output
-WorkspaceActionImpl Workspace
[4]{3}StepStartNode Allocate node : Body : Start
-BodyInvocationAction null
[5]{4}StepAtomNode Build
-LogActionImpl Console Output
-LabelAction Build
-StageActionImpl null
[6]{5}StepAtomNode Print Message
-LogActionImpl Console Output
[7]{6}StepAtomNode Test
-LogActionImpl Console Output
-LabelAction Test
-StageActionImpl null
[8]{7}StepAtomNode Print Message
-LogActionImpl Console Output
[9]{8}StepAtomNode Deploy
-LogActionImpl Console Output
-LabelAction Deploy
-StageActionImpl null
[10]{9}StepAtomNode Write file to workspace
[11]{10}StepAtomNode Archive artifacts
-LogActionImpl Console Output
[12]{11}StepAtomNode Print Message
-LogActionImpl Console Output
[13]{12}StepEndNode Allocate node : Body : End [st=4]
-BodyInvocationAction null
[14]{13}StepEndNode Allocate node : End [st=3]
[15]{14}FlowEndNode End of Pipeline [st=2]
*/

WorkflowRun build = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

ForkScanner scan = new ForkScanner();
scan.setup(build.getExecution().getCurrentHeads());
CollectingChunkVisitor visitor = new CollectingChunkVisitor();
scan.visitSimpleChunks(visitor, new StageChunkFinder());
List<MemoryFlowChunk> stages = visitor.getChunks();

Assert.assertEquals(3, stages.size());
assertChunkBoundary(stages.get(0), 4, 5, 6, 7);
assertChunkBoundary(stages.get(1), 6, 7, 8, 9);
assertChunkBoundary(stages.get(2), 8, 9, 15, -1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testBasicPass() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Passes");
job.setDefinition(new CpsFlowDefinition("" +
"sleep 1 \n" +
"stage 'first' \n" +
"echo 'first stage' \n" +
"sleep 1 \n" +
"echo 'done' \n", true));

Expand Down Expand Up @@ -188,7 +188,7 @@ public void testFail() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Fails");
job.setDefinition(new CpsFlowDefinition("" +
"sleep 1 \n" +
"stage 'first' \n" +
"echo 'first stage' \n" +
"sleep 1 \n" +
"error('fails') \n", true));
/* Node dump follows, format:
Expand Down Expand Up @@ -235,7 +235,7 @@ public void testFail() throws Exception {
public void testBasicParallelFail() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Fails");
job.setDefinition(new CpsFlowDefinition("" +
"stage 'primero'\n" +
"echo 'primero stage'\n" +
"def branches = ['failFast': false]\n" +
"branches['success'] = {sleep 1; echo 'succeed'}\n" +
"branches['fail'] = {error('autofail');}\n" +
Expand Down Expand Up @@ -342,7 +342,7 @@ public void testInProgress() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Fails");
job.setDefinition(new CpsFlowDefinition("" +
"sleep 1 \n" +
"stage 'first' \n" +
"echo 'first stage' \n" +
"sleep 1 \n" +
"semaphore('wait') \n", true));
WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
Expand All @@ -362,7 +362,7 @@ public void testInProgress() throws Exception {
public void timingTest() throws Exception {
// Problem here: for runs in progress we should be using current time if they're the last run node, aka the in-progress node
String jobScript = ""+
"stage 'first'\n" +
"echo 'first stage'\n" +
"parallel 'long' : { sleep 10; }, \n" +
" 'short': { sleep 2; }";

Expand Down Expand Up @@ -398,7 +398,7 @@ public void timingTest() throws Exception {
public void testInProgressParallel() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "Fails");
job.setDefinition(new CpsFlowDefinition("" +
"stage 'primero'\n" +
"echo 'primero stage'\n" +
"def branches = ['failFast': false]\n" +
"branches['success'] = {echo 'succeed'}\n" +
"branches['pause'] = { sleep 1; semaphore 'wait'; }\n" +
Expand Down Expand Up @@ -483,7 +483,7 @@ public void testInProgressParallel() throws Exception {
public void inputTest() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "InputJob");
job.setDefinition(new CpsFlowDefinition("" + // FlowStartNode: ID 2
"stage 'first' \n" + // FlowNode 3
"echo 'first stage' \n" + // FlowNode 3
"echo 'print something' \n" + // FlowNode 4
"input 'prompt' \n", true)); // FlowNode 5, end node will be #6
QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0);
Expand Down