From 25607db9b3e0ce926e457da36ccdb665bb2c1e65 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 14:20:52 -0400 Subject: [PATCH 01/14] Update README for CredentialsPlugin usage --- README.md | 2 +- docs/CredentialsPlugin.md | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5e4f2004..5c44a537 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ The example above gives you a bare-bones pipeline, and there may be Jenkinsfile * [ConditionalApplyPlugin](./docs/ConditionalApplyPlugin.md): only allow apply on master branch. * [DefaultEnvironmentPlugin](./docs/DefaultEnvironmentPlugin.md): automatically set `TF_VAR_environment` variable. ### Credentials and Configuration Management -* [CredentialsPlugin](./docs/CredentialsPlugin.md): Inject Jenkins credentials into your BuildStage. +* [CredentialsPlugin](./docs/CredentialsPlugin.md): Inject Jenkins credentials into your stages. * [FileParametersPlugin](./docs/FileParametersPlugin.md): Use properties files to inject environment-specific variables. * [ParameterStoreBuildWrapperPlugin](./docs/ParameterStoreBuildWrapperPlugin.md): Inject environment-specific variables using `withAwsParameterStore`. * [ParameterStoreExecPlugin](./docs/ParameterStoreExecPlugin.md): Inject environment-specific variables using parameter-store-exec. diff --git a/docs/CredentialsPlugin.md b/docs/CredentialsPlugin.md index 0be81199..e75c87ac 100644 --- a/docs/CredentialsPlugin.md +++ b/docs/CredentialsPlugin.md @@ -1,12 +1,12 @@ ## [CredentialsPlugin](../src/CredentialsPlugin.groovy) -Enable this plugin to inject credentials into your BuildStage using the [Jenkins Credentials Plugin](https://wiki.jenkins.io/display/JENKINS/Credentials+Plugin). +Enable this plugin to inject credentials into your stages using the [Jenkins Credentials Plugin](https://wiki.jenkins.io/display/JENKINS/Credentials+Plugin). One-time setup: * Install the [Jenkins Credentials Plugin](https://wiki.jenkins.io/display/JENKINS/Credentials+Plugin) on your Jenkins master. * Define a credential that you want to inject. Currently, only usernamePassword credentials are supported. -Specify the credential that you want to inject during the BuildStage. Optionally provide custom username/password environment variables that will contain the credential values for your use. +Specify the credential that you want to inject in your stages. Optionally provide custom username/password environment variables that will contain the credential values for your use. ``` // Jenkinsfile @@ -14,17 +14,19 @@ Specify the credential that you want to inject during the BuildStage. Optionall Jenkinsfile.init(this) +// MY_CREDENTIALS_USERNAME and MY_CREDENTIALS_PASSWORD will contain the respective username/password values of the 'my-credentials' credential. CredentialsPlugin.withBuildCredentials('my-credentials').init() def validate = new TerraformValidateStage() -// MY_CREDENTIALS_USERNAME and MY_CREDENTIALS_PASSWORD will contain the respective username/password values of the 'my-credentials' credential. def build = new BuildStage() -def deployQA = new TerraformEnvironmentStage('qa') +def deployQa = new TerraformEnvironmentStage('qa') +def testQa = new RegressionStage() def deployUat = new TerraformEnvironmentStage('uat') def deployProd = new TerraformEnvironmentStage('prod') validate.then(build) - .then(deployQA) + .then(deployQa) + .then(testQa) .then(deployUat) .then(deployProd) .build() From fa35c88162854ea5bdb8e409d22f2cdde4290ad4 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 15:18:09 -0400 Subject: [PATCH 02/14] Test coverage for existing BuildStage --- test/CredentialsPluginTest.groovy | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/CredentialsPluginTest.groovy b/test/CredentialsPluginTest.groovy index 70075823..2180e6c9 100644 --- a/test/CredentialsPluginTest.groovy +++ b/test/CredentialsPluginTest.groovy @@ -5,6 +5,10 @@ import static org.hamcrest.Matchers.instanceOf import static org.hamcrest.Matchers.is import static org.hamcrest.Matchers.notNullValue import static org.junit.Assert.assertThat +import static org.mockito.Mockito.mock +import static org.mockito.Mockito.spy +import static org.mockito.Mockito.verify +import static org.mockito.Mockito.any import org.junit.After import org.junit.Test @@ -139,5 +143,17 @@ class CredentialsPluginTest { assertThat(results['passwordVariable'], is(equalTo(customPasswordVariable))) } } + + class Apply { + @Test + void decoratesTheBuildStage() { + def buildStage = mock(BuildStage.class) + def plugin = spy(new CredentialsPlugin()) + + plugin.apply(buildStage) + + verify(buildStage).decorate(any(Closure.class)) + } + } } From 4b794ec604f45ab5c3c8dc5b5e54b43c21c024fd Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 14:24:02 -0400 Subject: [PATCH 03/14] Add CredentialsPlugin.apply(RegressionStage) --- src/CredentialsPlugin.groovy | 8 +++++++- test/CredentialsPluginTest.groovy | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/CredentialsPlugin.groovy b/src/CredentialsPlugin.groovy index ee939c50..26af8901 100644 --- a/src/CredentialsPlugin.groovy +++ b/src/CredentialsPlugin.groovy @@ -1,4 +1,4 @@ -class CredentialsPlugin implements BuildStagePlugin { +class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin { private static globalBuildCredentials = [] private buildCredentials = [] @@ -6,6 +6,7 @@ class CredentialsPlugin implements BuildStagePlugin { def plugin = new CredentialsPlugin() BuildStage.addPlugin(plugin) + RegressionStage.addPlugin(plugin) } public CredentialsPlugin() { @@ -24,6 +25,11 @@ class CredentialsPlugin implements BuildStagePlugin { buildStage.decorate(addBuildCredentials()) } + @Override + public void apply(RegressionStage regressionStage) { + regressionStage.decorate(addBuildCredentials()) + } + private addBuildCredentials() { def credentials = this.buildCredentials return { closure -> diff --git a/test/CredentialsPluginTest.groovy b/test/CredentialsPluginTest.groovy index 2180e6c9..d2aa4110 100644 --- a/test/CredentialsPluginTest.groovy +++ b/test/CredentialsPluginTest.groovy @@ -21,6 +21,7 @@ class CredentialsPluginTest { @After void resetPlugins() { BuildStage.resetPlugins() + RegressionStage.resetPlugins() CredentialsPlugin.reset() } @@ -32,6 +33,15 @@ class CredentialsPluginTest { assertThat(actualPlugins, hasItem(instanceOf(CredentialsPlugin.class))) } + + @Test + void modifiesRegressionStage() { + CredentialsPlugin.init() + + Collection actualPlugins = RegressionStage.getPlugins() + + assertThat(actualPlugins, hasItem(instanceOf(CredentialsPlugin.class))) + } } public class WithBuildCredentials { @@ -154,6 +164,16 @@ class CredentialsPluginTest { verify(buildStage).decorate(any(Closure.class)) } + + @Test + void decoratesTheRegressionStage() { + def testStage = mock(RegressionStage.class) + def plugin = spy(new CredentialsPlugin()) + + plugin.apply(testStage) + + verify(testStage).decorate(any(Closure.class)) + } } } From a0adbd50b8168965c9c86953b61f85a223bdaba8 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 15:44:58 -0400 Subject: [PATCH 04/14] Add CredentialsPlugin.apply(TerraformEnvironmentStage) --- src/CredentialsPlugin.groovy | 8 +++++++- src/TerraformEnvironmentStage.groovy | 4 ++++ test/CredentialsPluginTest.groovy | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/CredentialsPlugin.groovy b/src/CredentialsPlugin.groovy index 26af8901..2514b4f0 100644 --- a/src/CredentialsPlugin.groovy +++ b/src/CredentialsPlugin.groovy @@ -1,4 +1,4 @@ -class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin { +class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin, TerraformEnvironmentStagePlugin { private static globalBuildCredentials = [] private buildCredentials = [] @@ -7,6 +7,7 @@ class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin { BuildStage.addPlugin(plugin) RegressionStage.addPlugin(plugin) + TerraformEnvironmentStage.addPlugin(plugin) } public CredentialsPlugin() { @@ -30,6 +31,11 @@ class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin { regressionStage.decorate(addBuildCredentials()) } + @Override + public void apply(TerraformEnvironmentStage environmentStage) { + environmentStage.decorate(addBuildCredentials()) + } + private addBuildCredentials() { def credentials = this.buildCredentials return { closure -> diff --git a/src/TerraformEnvironmentStage.groovy b/src/TerraformEnvironmentStage.groovy index 76c317bc..015c7dd0 100644 --- a/src/TerraformEnvironmentStage.groovy +++ b/src/TerraformEnvironmentStage.groovy @@ -88,6 +88,10 @@ class TerraformEnvironmentStage implements Stage { } } + public void decorate(Closure decoration) { + decorations.add(ALL, decoration) + } + public decorate(String stageName, Closure decoration) { decorations.add(stageName, decoration) } diff --git a/test/CredentialsPluginTest.groovy b/test/CredentialsPluginTest.groovy index d2aa4110..599889a7 100644 --- a/test/CredentialsPluginTest.groovy +++ b/test/CredentialsPluginTest.groovy @@ -22,6 +22,7 @@ class CredentialsPluginTest { void resetPlugins() { BuildStage.resetPlugins() RegressionStage.resetPlugins() + TerraformEnvironmentStage.resetPlugins() CredentialsPlugin.reset() } @@ -42,6 +43,15 @@ class CredentialsPluginTest { assertThat(actualPlugins, hasItem(instanceOf(CredentialsPlugin.class))) } + + @Test + void modifiesTerraformEnvironmentStage() { + CredentialsPlugin.init() + + Collection actualPlugins = TerraformEnvironmentStage.getPlugins() + + assertThat(actualPlugins, hasItem(instanceOf(CredentialsPlugin.class))) + } } public class WithBuildCredentials { @@ -174,6 +184,16 @@ class CredentialsPluginTest { verify(testStage).decorate(any(Closure.class)) } + + @Test + void decoratesTheTerraformEnvironmentStage() { + def environment = mock(TerraformEnvironmentStage.class) + def plugin = spy(new CredentialsPlugin()) + + plugin.apply(environment) + + verify(environment).decorate(any(Closure.class)) + } } } From 487c5f89b3d567515be5e4d32019bde9d6831da9 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 16:09:40 -0400 Subject: [PATCH 05/14] Add CredentialsPlugin.apply(TerraformValidateStage) --- src/CredentialsPlugin.groovy | 8 +++++++- src/TerraformValidateStage.groovy | 4 ++++ test/CredentialsPluginTest.groovy | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/CredentialsPlugin.groovy b/src/CredentialsPlugin.groovy index 2514b4f0..3ec555aa 100644 --- a/src/CredentialsPlugin.groovy +++ b/src/CredentialsPlugin.groovy @@ -1,4 +1,4 @@ -class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin, TerraformEnvironmentStagePlugin { +class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin, TerraformEnvironmentStagePlugin, TerraformValidateStagePlugin { private static globalBuildCredentials = [] private buildCredentials = [] @@ -8,6 +8,7 @@ class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin, Terr BuildStage.addPlugin(plugin) RegressionStage.addPlugin(plugin) TerraformEnvironmentStage.addPlugin(plugin) + TerraformValidateStage.addPlugin(plugin) } public CredentialsPlugin() { @@ -36,6 +37,11 @@ class CredentialsPlugin implements BuildStagePlugin, RegressionStagePlugin, Terr environmentStage.decorate(addBuildCredentials()) } + @Override + public void apply(TerraformValidateStage validateStage) { + validateStage.decorate(addBuildCredentials()) + } + private addBuildCredentials() { def credentials = this.buildCredentials return { closure -> diff --git a/src/TerraformValidateStage.groovy b/src/TerraformValidateStage.groovy index 39ab32ec..f69c8c31 100644 --- a/src/TerraformValidateStage.groovy +++ b/src/TerraformValidateStage.groovy @@ -41,6 +41,10 @@ class TerraformValidateStage implements Stage { } } + public decorate(Closure decoration) { + decorations.add(ALL, decoration) + } + public decorate(String stageName, Closure decoration) { decorations.add(stageName, decoration) } diff --git a/test/CredentialsPluginTest.groovy b/test/CredentialsPluginTest.groovy index 599889a7..0848f86e 100644 --- a/test/CredentialsPluginTest.groovy +++ b/test/CredentialsPluginTest.groovy @@ -23,6 +23,7 @@ class CredentialsPluginTest { BuildStage.resetPlugins() RegressionStage.resetPlugins() TerraformEnvironmentStage.resetPlugins() + TerraformValidateStage.resetPlugins() CredentialsPlugin.reset() } @@ -194,6 +195,16 @@ class CredentialsPluginTest { verify(environment).decorate(any(Closure.class)) } + + @Test + void decoratesTheTerraformValidateStage() { + def environment = mock(TerraformValidateStage.class) + def plugin = spy(new CredentialsPlugin()) + + plugin.apply(environment) + + verify(environment).decorate(any(Closure.class)) + } } } From dace6cef419727e9c6e4564ad88cb62e45d0e0fe Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Tue, 7 Apr 2020 16:18:55 -0400 Subject: [PATCH 06/14] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1b99ab..a883866f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +* [Issue #192](https://github.com/manheim/terraform-pipeline/issues/192) Apply CredentialsPlugins to all Stages, not just BuildStage + # v5.5 * [Issue #151](https://github.com/manheim/terraform-pipeline/issues/151) Fix CPS mismatch errors, reduce meta magic in Jenkinsfile.groovy and Stage decorations From 766b2afa44a49772daa978efca1a1d1803e8ed04 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 8 Apr 2020 15:19:59 -0400 Subject: [PATCH 07/14] Update README for ParameterStoreBuildWrapper --- docs/ParameterStoreBuildWrapperPlugin.md | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/ParameterStoreBuildWrapperPlugin.md b/docs/ParameterStoreBuildWrapperPlugin.md index 6abb9cff..3d63abb4 100644 --- a/docs/ParameterStoreBuildWrapperPlugin.md +++ b/docs/ParameterStoreBuildWrapperPlugin.md @@ -32,3 +32,32 @@ validate.then(deployQA) .then(deployProd) .build() ``` + +Optionally, you can override the default ParameterStore path with your own custom pattern. + +``` +// Jenkinsfile +@Library(['terraform-pipeline@v5.0']) _ + +Jenkinsfile.init(this) + +// Enable ParameterStoreBuildWrapperPlugin with a custom path pattern +ParameterStoreBuildWrapperPlugin.withPathPattern { options -> "/${options['organization']}/${options['environment']}/${options['repoName']}" } + .init() + +def validate = new TerraformValidateStage() + +// Inject all parameters in //qa/ +def deployQA = new TerraformEnvironmentStage('qa') + +// Inject all parameters in //uat/ +def deployUat = new TerraformEnvironmentStage('uat') + +// Inject all parameters in //prod/ +def deployProd = new TerraformEnvironmentStage('prod') + +validate.then(deployQA) + .then(deployUat) + .then(deployProd) + .build() +``` From 93524f6ba0ea851b42bcfa23d7e05e7bcc0609dc Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 8 Apr 2020 16:39:53 -0400 Subject: [PATCH 08/14] Refactor: use options when constructing path --- src/ParameterStoreBuildWrapperPlugin.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ParameterStoreBuildWrapperPlugin.groovy b/src/ParameterStoreBuildWrapperPlugin.groovy index 9f80ee9c..583666e0 100644 --- a/src/ParameterStoreBuildWrapperPlugin.groovy +++ b/src/ParameterStoreBuildWrapperPlugin.groovy @@ -23,8 +23,11 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi String pathForEnvironment(String environment) { String organization = Jenkinsfile.instance.getOrganization() String repoName = Jenkinsfile.instance.getRepoName() + def options = [ environment: environment, + repoName: repoName, + organization: organization ] - return "/${organization}/${repoName}/${environment}/" + return "/${options['organization']}/${options['repoName']}/${options['environment']}/" } public static Closure addParameterStoreBuildWrapper(Map options = []) { From f7d574b805c73ed79d024ed84797c93b6cdf0708 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 8 Apr 2020 16:44:28 -0400 Subject: [PATCH 09/14] Refactor: use Closure for pattern --- src/ParameterStoreBuildWrapperPlugin.groovy | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ParameterStoreBuildWrapperPlugin.groovy b/src/ParameterStoreBuildWrapperPlugin.groovy index 583666e0..b366abb7 100644 --- a/src/ParameterStoreBuildWrapperPlugin.groovy +++ b/src/ParameterStoreBuildWrapperPlugin.groovy @@ -23,11 +23,13 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi String pathForEnvironment(String environment) { String organization = Jenkinsfile.instance.getOrganization() String repoName = Jenkinsfile.instance.getRepoName() - def options = [ environment: environment, - repoName: repoName, - organization: organization ] + def patternOptions = [ environment: environment, + repoName: repoName, + organization: organization ] - return "/${options['organization']}/${options['repoName']}/${options['environment']}/" + def pathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" } + + return pathPattern(patternOptions) } public static Closure addParameterStoreBuildWrapper(Map options = []) { From 0b48c61cf6fc2b6bb4e3f93a9a4344a04c64f984 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 8 Apr 2020 16:59:01 -0400 Subject: [PATCH 10/14] Refactor: Make pattern an instance variable --- src/ParameterStoreBuildWrapperPlugin.groovy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ParameterStoreBuildWrapperPlugin.groovy b/src/ParameterStoreBuildWrapperPlugin.groovy index b366abb7..8d8c0df6 100644 --- a/src/ParameterStoreBuildWrapperPlugin.groovy +++ b/src/ParameterStoreBuildWrapperPlugin.groovy @@ -2,10 +2,16 @@ import static TerraformEnvironmentStage.PLAN import static TerraformEnvironmentStage.APPLY class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugin { + private pathPattern + public static void init() { TerraformEnvironmentStage.addPlugin(new ParameterStoreBuildWrapperPlugin()) } + public ParameterStoreBuildWrapperPlugin() { + pathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" } + } + @Override public void apply(TerraformEnvironmentStage stage) { def environment = stage.getEnvironment() @@ -27,8 +33,6 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi repoName: repoName, organization: organization ] - def pathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" } - return pathPattern(patternOptions) } From 38f246b01e7700f7e32b5bb7f3c9eba937bc95bf Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Wed, 8 Apr 2020 17:43:26 -0400 Subject: [PATCH 11/14] Allow pattern to be customized globally --- src/ParameterStoreBuildWrapperPlugin.groovy | 13 ++++++++++--- ...ParameterStoreBuildWrapperPluginTest.groovy | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/ParameterStoreBuildWrapperPlugin.groovy b/src/ParameterStoreBuildWrapperPlugin.groovy index 8d8c0df6..46c4613a 100644 --- a/src/ParameterStoreBuildWrapperPlugin.groovy +++ b/src/ParameterStoreBuildWrapperPlugin.groovy @@ -2,14 +2,15 @@ import static TerraformEnvironmentStage.PLAN import static TerraformEnvironmentStage.APPLY class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugin { - private pathPattern + private static globalPathPattern + private static defaultPathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" } public static void init() { TerraformEnvironmentStage.addPlugin(new ParameterStoreBuildWrapperPlugin()) } - public ParameterStoreBuildWrapperPlugin() { - pathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" } + public static withPathPattern(Closure newPathPattern) { + globalPathPattern = newPathPattern } @Override @@ -33,6 +34,8 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi repoName: repoName, organization: organization ] + def pathPattern = globalPathPattern ?: defaultPathPattern + return pathPattern(patternOptions) } @@ -49,4 +52,8 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi } } } + + public static reset() { + globalPathPattern = null + } } diff --git a/test/ParameterStoreBuildWrapperPluginTest.groovy b/test/ParameterStoreBuildWrapperPluginTest.groovy index e75db74f..b828a22b 100644 --- a/test/ParameterStoreBuildWrapperPluginTest.groovy +++ b/test/ParameterStoreBuildWrapperPluginTest.groovy @@ -31,6 +31,7 @@ class ParameterStoreBuildWrapperPluginTest { @After public void reset() { Jenkinsfile.instance = null + ParameterStoreBuildWrapperPlugin.reset() } private configureJenkins(Map config = [:]) { @@ -51,7 +52,22 @@ class ParameterStoreBuildWrapperPluginTest { ParameterStoreBuildWrapperPlugin plugin = new ParameterStoreBuildWrapperPlugin() String actual = plugin.pathForEnvironment(environment) - assertEquals(actual, "/${organization}/${repoName}/${environment}/".toString()) + assertEquals("/${organization}/${repoName}/${environment}/".toString(), actual) + } + + @Test + void usesCustomPatternWhenProvided() { + String organization = "MyOrg" + String repoName = "MyRepo" + String environment = "qa" + Closure customPattern = { options -> "/foo/${options['organization']}/${options['environment']}/${options['repoName']}" } + + configureJenkins(repoName: repoName, organization: organization) + ParameterStoreBuildWrapperPlugin.withPathPattern(customPattern) + ParameterStoreBuildWrapperPlugin plugin = new ParameterStoreBuildWrapperPlugin() + + String actual = plugin.pathForEnvironment(environment) + assertEquals("/foo/${organization}/${environment}/${repoName}".toString(), actual) } } } From 32e242b5a163877bd8b34c8ccc246d228113597f Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Thu, 9 Apr 2020 00:28:49 -0400 Subject: [PATCH 12/14] Ensure withPathPattern is fluent --- src/ParameterStoreBuildWrapperPlugin.groovy | 1 + test/ParameterStoreBuildWrapperPluginTest.groovy | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ParameterStoreBuildWrapperPlugin.groovy b/src/ParameterStoreBuildWrapperPlugin.groovy index 46c4613a..84123de2 100644 --- a/src/ParameterStoreBuildWrapperPlugin.groovy +++ b/src/ParameterStoreBuildWrapperPlugin.groovy @@ -11,6 +11,7 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi public static withPathPattern(Closure newPathPattern) { globalPathPattern = newPathPattern + return this } @Override diff --git a/test/ParameterStoreBuildWrapperPluginTest.groovy b/test/ParameterStoreBuildWrapperPluginTest.groovy index b828a22b..1dc2f021 100644 --- a/test/ParameterStoreBuildWrapperPluginTest.groovy +++ b/test/ParameterStoreBuildWrapperPluginTest.groovy @@ -70,5 +70,19 @@ class ParameterStoreBuildWrapperPluginTest { assertEquals("/foo/${organization}/${environment}/${repoName}".toString(), actual) } } + + class WithPathPattern { + @After + public void reset() { + ParameterStoreBuildWrapperPlugin.reset() + } + + @Test + void isFluent() { + def result = ParameterStoreBuildWrapperPlugin.withPathPattern { options -> 'somePattern' } + + assertEquals(ParameterStoreBuildWrapperPlugin.class, result) + } + } } From 282bfa443b8958568f4a2ed427ceea53e7a454b8 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Thu, 9 Apr 2020 00:55:44 -0400 Subject: [PATCH 13/14] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a883866f..b1a98bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +* [Issue #203](https://github.com/manheim/terraform-pipeline/issues/201) ParameterStoreBuildWrapperPlugin - allow path to be customized * [Issue #192](https://github.com/manheim/terraform-pipeline/issues/192) Apply CredentialsPlugins to all Stages, not just BuildStage # v5.5 From 4e964776c4049d66ee197b7266cb599217486f77 Mon Sep 17 00:00:00 2001 From: Keith Manning Date: Thu, 9 Apr 2020 01:07:48 -0400 Subject: [PATCH 14/14] Update CHANGELOG for v5.6 release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a98bc8..268686ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +# v5.6 + * [Issue #203](https://github.com/manheim/terraform-pipeline/issues/201) ParameterStoreBuildWrapperPlugin - allow path to be customized * [Issue #192](https://github.com/manheim/terraform-pipeline/issues/192) Apply CredentialsPlugins to all Stages, not just BuildStage