-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
expose custom env vars for run step runner for custom steps #229
Conversation
Codecov Report
@@ Coverage Diff @@
## master #229 +/- ##
==========================================
+ Coverage 70.07% 70.15% +0.07%
==========================================
Files 61 61
Lines 3579 3588 +9
==========================================
+ Hits 2508 2517 +9
Misses 892 892
Partials 179 179
Continue to review full report at Codecov.
|
@@ -34,6 +34,9 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command []string, | |||
fmt.Sprintf("ATLANTIS_TERRAFORM_VERSION=%s", tfVersion), | |||
fmt.Sprintf("DIR=%s", path), | |||
fmt.Sprintf("PLANFILE=%s", filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectConfig))), | |||
fmt.Sprintf("REPO_OWNER=%s", ctx.BaseRepo.Owner), | |||
fmt.Sprintf("REPO_NAME=%s", ctx.BaseRepo.Name), | |||
fmt.Sprintf("BRANCH_NAME=%s", ctx.Pull.Branch), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get everything in there:
baseEnvVars := os.Environ()
customEnvVars := map[string]string{
"WORKSPACE": ctx.Workspace,
"ATLANTIS_TERRAFORM_VERSION": tfVersion,
"DIR": path,
"PLANFILE": filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectConfig)),
"BASE_REPO_NAME": ctx.BaseRepo.Name,
"BASE_REPO_OWNER": ctx.BaseRepo.Owner,
"HEAD_REPO_NAME": ctx.HeadRepo.Name,
"HEAD_REPO_OWNER": ctx.HeadRepo.Owner,
"HEAD_BRANCH_NAME": ctx.Pull.Branch,
"PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num),
"PULL_AUTHOR": ctx.Pull.Author,
}
finalEnvVars := baseEnvVars
for key, val := range customEnvVars {
finalEnvVars = append(finalEnvVars, fmt.Sprintf("%s=%s", key, val))
}
cmd.Env = finalEnvVars
We also need to update the tests. Can do something like the last case of run_step_runner_test.go
:
{
Command: "echo workspace=$WORKSPACE version=$ATLANTIS_TERRAFORM_VERSION dir=$DIR planfile=$PLANFILE",
ExpOut: "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/myworkspace.tfplan\n",
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. I'll make the additions and push it up later this evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and we'll also need to update the docs: https://github.com/runatlantis/atlantis/blob/master/runatlantis.io/docs/atlantis-yaml-reference.md#custom-run-command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
Thanks for the suggestions @lkysow. This should do it. |
Thanks! This is great. I added a small change to the tests and squashed your commits in #232. This will be in the next release. |
No description provided.