Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Enable stage filter argument for the beatsStages (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Apr 20, 2021
1 parent 8f48394 commit d0e1c50
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/test/groovy/BeatsStagesStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,38 @@ class BeatsStagesStepTests extends ApmBasePipelineTest {
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-multi-when'))
assertJobStatusSuccess()
}

@Test
void test_simple_stage_without_match() throws Exception {
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"mage" : [ "foo" ],
"stage" : "mandatory"
]
]
], function: new RunCommand(steps: this), filterStage: "optional")
printCallStack()
assertTrue(ret.size() == 0)
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-simple'))
assertJobStatusSuccess()
}

@Test
void test_simple_stage_with_match() throws Exception {
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"mage" : [ "foo" ],
"stage" : "mandatory"
]
]
], function: new RunCommand(steps: this), filterStage: "mandatory")
printCallStack()
assertTrue(ret.size() == 1)
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-simple'))
assertJobStatusSuccess()
}
}
1 change: 1 addition & 0 deletions vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ base64encode(text: "text to encode", encoding: "UTF-8")
<li>project: the name of the project. Mandatory</li>
<li>content: the content with all the stages and commands to be transformed. Mandatory</li>
<li>function: the function to be called. Should implement the class BeatsFunction. Mandatory</li>
<li>filterStage: the name of the stage to be filtered. Optional</li>
</ul>
</p>

Expand Down
11 changes: 10 additions & 1 deletion vars/beatsStages.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Map call(Map args = [:]){
def project = args.containsKey('project') ? args.project : error('beatsStages: project parameter is required')
def content = args.containsKey('content') ? args.content : error('beatsStages: content parameter is required')
def function = args.containsKey('function') ? args.function : error('beatsStages: function parameter is required')
def filterStage = args.get('filterStage', '')
def defaultNode = content.containsKey('platform') ? content.platform : error('beatsStages: platform entry in the content is required.')

def mapOfStages = [:]
Expand All @@ -35,7 +36,15 @@ Map call(Map args = [:]){
} else {
tempMapOfStages = generateStages(content: value, project: project, stageName: stageName, defaultNode: defaultNode, function: function)
}
tempMapOfStages.each { k,v -> mapOfStages["${k}"] = v }

// This should help to filter stages by their stage name and ignore if they don't match
if (value.containsKey('stage') && filterStage?.trim()) {
if (value.get('stage').equals(filterStage)) {
tempMapOfStages.each { k,v -> mapOfStages["${k}"] = v }
}
} else {
tempMapOfStages.each { k,v -> mapOfStages["${k}"] = v }
}
}

return mapOfStages
Expand Down
1 change: 1 addition & 0 deletions vars/beatsStages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<li>project: the name of the project. Mandatory</li>
<li>content: the content with all the stages and commands to be transformed. Mandatory</li>
<li>function: the function to be called. Should implement the class BeatsFunction. Mandatory</li>
<li>filterStage: the name of the stage to be filtered. Optional</li>
</ul>
</p>

Expand Down

0 comments on commit d0e1c50

Please sign in to comment.