Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support global/project/step env even if buildkite trigger step is used #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 21 additions & 1 deletion pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,28 @@ func generatePipeline(steps []interface{}, pipelineEnv map[string]string, projec

env, foundEnv := stepMap["env"].(map[interface{}]interface{})
_, foundBlockStep := stepMap["block"].(string)
_, foundTriggerStep := stepMap["trigger"].(string)

if !foundBlockStep {
if foundTriggerStep {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to add a short comment describing the transformation that is being done in this block.

// Is there a build property
build, foundBuild := stepMap["build"].(map[interface{}]interface{})

if (!foundBuild) {
build = make(map[interface{}]interface{}) // TODO allow nesting
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please clarify this TODO?
This will help other people pick this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I think it's errant. I'll remove.

stepMap["build"] = build
}

buildEnv, foundBuildEnv := build["env"].(map[interface{}]interface{})

if (!foundBuildEnv) {
buildEnv = make(map[interface{}]interface{})
build["env"] = buildEnv // env TODO add to build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify this TODO as well.
It seems like the line adds env to build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, errant comments. Apologies, will remove.

}

for envVarName, envVarValue := range pipelineEnv {
buildEnv[envVarName] = envVarValue
}
} else if !foundBlockStep {
if !foundEnv {
env = make(map[interface{}]interface{})
stepMap["env"] = env
Expand Down
20 changes: 20 additions & 0 deletions tests/dynamic_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ steps: # the same schema as regular buildkite pipeline steps
key: bootstrap
command:
- make bootstrap
- trigger: my-other-build-pipeline
label: trigger-another-pipeline # a non project scoped step (to test depends_on handling)
key: trigger-step
command:
- make trigger-step
- trigger: my-other-build-pipeline
label: trigger-another-pipeline # a non project scoped step (to test depends_on handling)
key: trigger-step
build:
env:
EXISTING_ENV_VAR: persisted
command:
- make trigger-step
- trigger: my-other-build-pipeline
label: trigger-another-pipeline # a non project scoped step (to test depends_on handling)
key: trigger-step
build:
message: 'has existing build key'
command:
- make trigger-step
- label: test
key: test
env:
Expand Down
26 changes: 26 additions & 0 deletions tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ steps:
TEST_ENV_PIPELINE: test-pipeline
key: bootstrap
label: bootstrap
- build:
env:
TEST_ENV_PIPELINE: test-pipeline
command:
- make trigger-step
key: trigger-step
label: trigger-another-pipeline
trigger: my-other-build-pipeline
- build:
env:
EXISTING_ENV_VAR: persisted
TEST_ENV_PIPELINE: test-pipeline
command:
- make trigger-step
key: trigger-step
label: trigger-another-pipeline
trigger: my-other-build-pipeline
- build:
env:
TEST_ENV_PIPELINE: test-pipeline
message: has existing build key
command:
- make trigger-step
key: trigger-step
label: trigger-another-pipeline
trigger: my-other-build-pipeline
- command:
- cd \$\$BUILDPIPE_PROJECT_PATH
- make test
Expand Down