Skip to content

Commit

Permalink
update apply logic and README
Browse files Browse the repository at this point in the history
  • Loading branch information
jleopold28 committed Jun 16, 2020
1 parent 282e9b5 commit c76898d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ The example above gives you a bare-bones pipeline, and there may be Jenkinsfile
* [ConfirmApplyPlugin](./docs/ConfirmApplyPlugin.md): pause and review the plan, before applying any changes.
* [ConditionalApplyPlugin](./docs/ConditionalApplyPlugin.md): only allow apply on master branch.
* [DefaultEnvironmentPlugin](./docs/DefaultEnvironmentPlugin.md): automatically set `TF_VAR_environment` variable.
* [TargetPlugin](./docs/TargetPlugin.md): set `-target` parameter for terraform plan and apply.
### Credentials and Configuration Management
* [CredentialsPlugin](./docs/CredentialsPlugin.md): Inject Jenkins credentials into your stages.
* [FileParametersPlugin](./docs/FileParametersPlugin.md): Use properties files to inject environment-specific variables.
Expand All @@ -117,6 +116,7 @@ The example above gives you a bare-bones pipeline, and there may be Jenkinsfile
* [TerraformDirectoryPlugin](./docs/TerraformDirectoryPlugin.md): Change the default directory containing your terraform code.
* [TerraformLandscapePlugin](./docs/TerraformLandscapePlugin.md): Enable terraform-landscape plan output.
* [TerraformPlanResultsPR](./docs/TerraformPlanResultsPR.md): Use this to post Terraform plan results in the comments of a PR.
* [TargetPlugin](./docs/TargetPlugin.md): set `-target` parameter for terraform plan and apply.

## Write your own Plugin

Expand Down
16 changes: 4 additions & 12 deletions src/TargetPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@ class TargetPlugin implements TerraformPlanCommandPlugin, TerraformApplyCommandP

@Override
public void apply(TerraformPlanCommand command) {
def targets = Jenkinsfile.instance.getEnv().RESOURCE_TARGETS
if ("${targets}" != '' && targets != null) {
for (item in "${targets}".split(',')) {
command.withArgument("-target ${item}")
}
}
def targets = Jenkinsfile.instance.getEnv().RESOURCE_TARGETS ?: ''
targets.split(',').each { item -> command.withArgument("-target ${item}") }
}

@Override
public void apply(TerraformApplyCommand command) {
def targets = Jenkinsfile.instance.getEnv().RESOURCE_TARGETS
if ("${targets}" != '' && targets != null) {
for (item in "${targets}".split(',')) {
command.withArgument("-target ${item}")
}
}
def targets = Jenkinsfile.instance.getEnv().RESOURCE_TARGETS ?: ''
targets.split(',').each { item -> command.withArgument("-target ${item}") }
}

@Override
Expand Down

0 comments on commit c76898d

Please sign in to comment.