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

2.0 pipeline steps for beats #689

Merged
merged 46 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5221261
beats 2.0 pipeline
v1v Jul 27, 2020
bd050f6
UTs: whenBranches
v1v Jul 27, 2020
769eca1
UTs: whenTags and whenParameters
v1v Jul 27, 2020
6278ea0
UTs: whenComments
v1v Jul 27, 2020
c65f130
UTs: whenLabels
v1v Jul 27, 2020
b2940bc
add license header
v1v Jul 27, 2020
f71a6fc
ITs: beatsWhen
v1v Jul 27, 2020
feae2ad
Add beats meta step
v1v Jul 27, 2020
d4bf9a3
ITs
v1v Jul 28, 2020
47879e9
beatsStages
v1v Jul 28, 2020
3e15f57
beatsStages support with beatsWhen
v1v Jul 28, 2020
afd55fc
beatsStages UTs
v1v Jul 28, 2020
0faa2f5
Add docs and UTs for the mandatory entries
v1v Jul 28, 2020
778bff6
Add TODO and generate markdwon with the when reasons
v1v Jul 28, 2020
61912a6
Support changeset with macros
v1v Jul 28, 2020
4e0d4dc
Enable function to be passed from the pipeline itself
v1v Jul 28, 2020
6f55dbd
Fix license header
v1v Jul 28, 2020
69343c1
Merge branch 'master' into feature/2.0-beats
v1v Jul 28, 2020
da8b068
Apply suggestions from code review
v1v Jul 29, 2020
873d027
As suggested in the code review
v1v Jul 29, 2020
71fe04c
As suggested in the code review
v1v Jul 29, 2020
799a0e2
Revert "As suggested in the code review"
v1v Jul 29, 2020
97a4065
Add markdown reasons
v1v Jul 29, 2020
dbcf337
Generate one master markdown with the build reasons
v1v Jul 29, 2020
519e93e
[markdown] easy to show the reasons
v1v Jul 29, 2020
1562f5c
Merge branch 'master' into feature/2.0-beats
v1v Jul 29, 2020
f964446
Add description to diff the when condition is the global one or the s…
v1v Jul 29, 2020
b242698
Merge branch 'feature/2.0-beats' of github.com:elastic/apm-pipeline-l…
v1v Jul 30, 2020
8d00b3b
Support disabled flag to easily disable a whole project or stage if r…
v1v Jul 30, 2020
8fb05e4
Use the stage name as the context for the GH check
v1v Jul 30, 2020
c9d7c0a
Support changesetFunction for the beatsWhen
v1v Jul 30, 2020
8b025e5
Docs
v1v Jul 30, 2020
e9e9e61
Add markdown collapse
v1v Jul 31, 2020
4db5fcf
Support beatsWhen with special token for some specific project depend…
v1v Jul 31, 2020
25f3a0b
Cosmetic change in the markdown
v1v Jul 31, 2020
c3b029b
Pass the unique ID to be consumed for the stashed map that's required…
v1v Aug 6, 2020
e9e7c1c
Merge remote-tracking branch 'upstream/master' into feature/2.0-beats
v1v Aug 6, 2020
5ef3587
Merge remote-tracking branch 'upstream/master' into feature/2.0-beats
v1v Sep 3, 2020
cb7b894
Fix wound up catching method mismatch with this.& by using a Class
v1v Sep 3, 2020
fa26c0f
Fix super-linter
v1v Sep 3, 2020
28f514e
Update vars/beatsWhen.groovy
v1v Sep 3, 2020
72bbcac
Revert "Fix super-linter"
v1v Sep 3, 2020
43f4e02
Merge remote-tracking branch 'upstream/master' into feature/2.0-beats
v1v Sep 3, 2020
0239e8b
Merge branch 'feature/2.0-beats' of github.com:elastic/apm-pipeline-l…
v1v Sep 3, 2020
ebfd449
Merge branch 'master' into feature/2.0-beats
v1v Sep 4, 2020
f4399e3
Merge branch 'master' into feature/2.0-beats
v1v Sep 14, 2020
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
5 changes: 4 additions & 1 deletion local/configs/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ unclassified:
globalConfigName: username
globalConfigEmail: username@example.com
jobs:
- file: "/var/pipeline-library/src/test/resources/folders/it.dsl"
- file: "/var/pipeline-library/src/test/resources/folders/beats.dsl"
- file: "/var/pipeline-library/src/test/resources/folders/getBuildInfoJsonFiles.dsl"
- file: "/var/pipeline-library/src/test/resources/folders/it.dsl"
- file: "/var/pipeline-library/src/test/resources/folders/timeout.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/beats/beatsStages.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/beats/beatsWhen.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/cancelPreviousRunningBuilds.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/cmd.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/dockerLogin.dsl"
Expand Down
1 change: 1 addition & 0 deletions src/test/groovy/ApmBasePipelineTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class ApmBasePipelineTest extends DeclarativePipelineTest {
return script.call(m)
})
helper.registerAllowedMethod('base64encode', [Map.class], { return "YWRtaW46YWRtaW4xMjMK" })
helper.registerAllowedMethod('beatsWhen', [Map.class], null)
helper.registerAllowedMethod('cancelPreviousRunningBuilds', [Map.class], null)
helper.registerAllowedMethod('cmd', [Map.class], { m ->
def script = loadScript('vars/cmd.groovy')
Expand Down
186 changes: 186 additions & 0 deletions src/test/groovy/BeatsStagesStepTests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import org.junit.Before
import org.junit.After
import org.junit.Test
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue

class BeatsStagesStepTests extends ApmBasePipelineTest {
String scriptName = 'vars/beatsStages.groovy'

def runCommand(Map args = [:]) {
echo "${args.label}"
}

@Override
@Before
void setUp() throws Exception {
super.setUp()
}

@Test
void test_with_no_data() throws Exception {
def script = loadScript(scriptName)
try {
script.call()
} catch (e) {
// NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'project param is required'))
assertJobStatusFailure()
}

@Test
void test_with_no_project() throws Exception {
def script = loadScript(scriptName)
try {
script.call(project: 'foo')
} catch (e) {
// NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'content param is required'))
assertJobStatusFailure()
}

@Test
void test_with_no_platform() throws Exception {
def script = loadScript(scriptName)
try {
script.call(project: 'foo', content: [:], function: this.&runCommand)
} catch (e) {
// NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'platform entry in the content is required'))
assertJobStatusFailure()
}

@Test
void test_with_no_function() throws Exception {
def script = loadScript(scriptName)
try {
script.call(project: 'foo', content: [:])
} catch (e) {
// NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'function param is required'))
assertJobStatusFailure()
}

@Test
void test_simple() throws Exception {
def script = loadScript(scriptName)
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"mage" : [ "foo" ]
]
]
], function: this.&runCommand)
printCallStack()
assertTrue(ret.size() == 1)
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-simple'))
assertJobStatusSuccess()
}

@Test
void test_multiple() throws Exception {
def script = loadScript(scriptName)
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"make" : [ "foo" ]
],
"multi" : [
"mage" : [ "foo" ],
"platforms" : [ 'windows-2019', 'windows-2016' ]
]
]
], function: this.&runCommand)
printCallStack()
assertTrue(ret.size() == 3)
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-simple'))
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-multi-windows-2019'))
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-multi-windows-2016'))
assertJobStatusSuccess()
}

@Test
void test_multiple_when_without_match() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('beatsWhen', [Map.class], {return false})
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"make" : [ "foo" ]
],
"multi" : [
"make" : [ "foo" ],
"platforms" : [ 'windows-2019' ]
],
"multi-when" : [
"mage" : [ "foo" ],
"platforms" : [ 'windows-2016' ],
"when" : [
"comments" : [ "/test auditbeat for windows" ]
]
]
]
], function: this.&runCommand)
printCallStack()
assertTrue(ret.size() == 2)
assertFalse(assertMethodCallContainsPattern('log', 'stage: foo-multi-when'))
assertJobStatusSuccess()
}

@Test
void test_multiple_when_with_match() throws Exception {
def script = loadScript(scriptName)
helper.registerAllowedMethod('beatsWhen', [Map.class], { return true })
def ret = script.call(project: 'foo', content: [
"platform" : [ "linux && ubuntu-16" ],
"stages": [
"simple" : [
"make" : [ "foo" ]
],
"multi" : [
"mage" : [ "foo" ],
"platforms" : [ 'windows-2019' ]
],
"multi-when" : [
"mage" : [ "foo" ],
"platforms" : [ 'windows-2016' ],
"when" : [
"comments" : [ "/test auditbeat for windows" ]
]
]
]
], function: this.&runCommand)
printCallStack()
assertTrue(ret.size() == 3)
assertTrue(assertMethodCallContainsPattern('log', 'stage: foo-multi-when'))
assertJobStatusSuccess()
}
}
Loading