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

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed May 18, 2020
1 parent c2cca9e commit 2476123
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion local/configs/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ jobs:
- file: "/var/pipeline-library/src/test/resources/jobs/cancelPreviousRunningBuilds.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/dockerLogin.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/downstream.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBeatsModule.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBuildInfoJsonFiles/abort.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBuildInfoJsonFiles/connectionRefused.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBuildInfoJsonFiles/error.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBuildInfoJsonFiles/success.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getBuildInfoJsonFiles/unstable.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/getGitMatchingGroup.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/git.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/gitBaseCommit.dsl"
- file: "/var/pipeline-library/src/test/resources/jobs/gitCheckout.dsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

class GetBeatsModuleStepTests extends ApmBasePipelineTest {
String scriptName = 'vars/getBeatsModule.groovy'
class GetGitMatchingGroupStepTests extends ApmBasePipelineTest {
String scriptName = 'vars/getGitMatchingGroup.groovy'

def realData = '''CHANGELOG.next.asciidoc
metricbeat/docs/modules/zookeeper.asciidoc
Expand Down Expand Up @@ -53,7 +53,7 @@ metricbeat/module/zookeeper/server/_meta/docs.asciidoc'''.stripMargin().stripInd
//NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'getBeatsModule: Missing pattern argument.'))
assertTrue(assertMethodCallContainsPattern('error', 'Missing pattern argument.'))
assertJobStatusFailure()
}

Expand All @@ -65,7 +65,7 @@ metricbeat/module/zookeeper/server/_meta/docs.asciidoc'''.stripMargin().stripInd
def module = script.call(pattern: 'foo')
printCallStack()
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertTrue(assertMethodCallContainsPattern('log', 'CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertJobStatusSuccess()
}

Expand Down Expand Up @@ -124,7 +124,7 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
helper.registerAllowedMethod('readFile', [String.class], { return changeset })
def module = script.call(pattern: '([^\\/]+)\\/.*')
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: not found'))
assertTrue(assertMethodCallContainsPattern('log', 'not found'))
assertJobStatusSuccess()
}

Expand All @@ -136,7 +136,7 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
def module = script.call(pattern: '^unknown.txt')
printCallStack()
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: not found with regex ^unknown.txt'))
assertTrue(assertMethodCallContainsPattern('log', 'not found with regex ^unknown.txt'))
assertJobStatusSuccess()
}

Expand All @@ -150,7 +150,7 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
//NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'getBeatsModule: windows is not supported yet.'))
assertTrue(assertMethodCallContainsPattern('error', 'windows is not supported yet.'))
assertJobStatusFailure()
}

Expand Down Expand Up @@ -218,7 +218,7 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
def module = script.call(pattern: '^foo/.*/file.txt', from: '', to: '')
printCallStack()
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertTrue(assertMethodCallContainsPattern('log', 'CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertJobStatusSuccess()
}

Expand All @@ -228,7 +228,7 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
def module = script.call(pattern: '^foo/.*/file.txt', to: '')
printCallStack()
assertEquals('', module)
assertTrue(assertMethodCallContainsPattern('log', 'getBeatsModule: CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertTrue(assertMethodCallContainsPattern('log', 'CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes.'))
assertJobStatusSuccess()
}

Expand Down
12 changes: 6 additions & 6 deletions vars/getBeatsModule.groovy → vars/getGitMatchingGroup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
- When exact match then all the files should match those patterns then it
returns the region otherwise and empty string.
def module = getBeatsModule(pattern: '([^\\/]+)\\/.*')
def module = getGitMatchingGroup(pattern: '([^\\/]+)\\/.*')
whenTrue(module.trim()) {
// ...
}
// Exclude the asciidoc files from the search.
def module = getBeatsModule(pattern: '([^\\/]+)\\/.*', exclude: '.*\\.asciidoc')
def module = getGitMatchingGroup(pattern: '([^\\/]+)\\/.*', exclude: '.*\\.asciidoc')
NOTE: This particular implementation requires to checkout with the step gitCheckout
*/
def call(Map params = [:]) {
if(!isUnix()){
error('getBeatsModule: windows is not supported yet.')
error('getGitMatchingGroup: windows is not supported yet.')
}
def pattern = params.containsKey('pattern') ? params.pattern : error('getBeatsModule: Missing pattern argument.')
def pattern = params.containsKey('pattern') ? params.pattern : error('getGitMatchingGroup: Missing pattern argument.')
def exclude = params.get('exclude', '')
def from = params.get('from', env.CHANGE_TARGET?.trim() ? "origin/${env.CHANGE_TARGET}" : env.GIT_PREVIOUS_COMMIT)
def to = params.get('to', env.GIT_BASE_COMMIT)
Expand All @@ -48,9 +48,9 @@ def call(Map params = [:]) {
if (from?.trim() && to?.trim()) {
def changes = sh(script: "git diff --name-only ${from}...${to} > ${gitDiffFile}", returnStdout: true)
group = getGroup(gitDiffFile, pattern, exclude)
log(level: 'INFO', text: "getBeatsModule: ${group.trim() ?: 'not found'} with regex ${pattern}")
log(level: 'INFO', text: "getGitMatchingGroup: ${group.trim() ?: 'not found'} with regex ${pattern}")
} else {
log(level: 'INFO', text: 'getBeatsModule: CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes. Or the from/to arguments are required.')
log(level: 'INFO', text: 'getGitMatchingGroup: CHANGE_TARGET or GIT_PREVIOUS_COMMIT and GIT_BASE_COMMIT env variables are required to evaluate the changes. Or the from/to arguments are required.')
}
return group
}
Expand Down
4 changes: 2 additions & 2 deletions vars/getBeatsModule.txt → vars/getGitMatchingGroup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ evaluates the change list and returns the module name.
NOTE: This particular implementation requires to checkout with the step gitCheckout

```
def module = getBeatsModule(pattern: '([^\\/]+)\\/.*')
def module = getGitMatchingGroup(pattern: '([^\\/]+)\\/.*')
whenTrue(module.trim()) {
// ...
}

// Exclude the asciidoc files from the search.
def module = getBeatsModule(pattern: '([^\\/]+)\\/.*', exclude: '.*\\.asciidoc')
def module = getGitMatchingGroup(pattern: '([^\\/]+)\\/.*', exclude: '.*\\.asciidoc')
```

* pattern: the regex pattern with the group to look for. Mandatory
Expand Down

0 comments on commit 2476123

Please sign in to comment.