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

expose custom env vars for run step runner for custom steps #229

Closed
wants to merge 5 commits into from
Closed
Changes from 2 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
3 changes: 3 additions & 0 deletions server/events/runtime/run_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

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",
		},

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

}
finalEnvVars := append(baseEnvVars, customEnvVars...)
cmd.Env = finalEnvVars
Expand Down