diff --git a/runatlantis.io/docs/atlantis-yaml-reference.md b/runatlantis.io/docs/atlantis-yaml-reference.md index aeb333db71..125a0d0c55 100644 --- a/runatlantis.io/docs/atlantis-yaml-reference.md +++ b/runatlantis.io/docs/atlantis-yaml-reference.md @@ -191,6 +191,7 @@ override the built-in `plan`/`apply` commands, ex. `run: terraform plan -out $PL * `BASE_BRANCH_NAME` - Name of the base branch of the pull request (the branch that the pull request is getting merged into) * `PULL_NUM` - Pull request number or ID, ex. `2`. * `PULL_AUTHOR` - Username of the pull request author, ex. `acme-user`. +* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`. ::: ::: tip diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index b7ddfc1074..7dd51f2a11 100644 --- a/server/events/runtime/run_step_runner.go +++ b/server/events/runtime/run_step_runner.go @@ -42,6 +42,7 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command []string, "BASE_BRANCH_NAME": ctx.Pull.BaseBranch, "PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num), "PULL_AUTHOR": ctx.Pull.Author, + "USER_NAME": ctx.User.Username, } finalEnvVars := baseEnvVars diff --git a/server/events/runtime/run_step_runner_test.go b/server/events/runtime/run_step_runner_test.go index ab674093ff..6716fef574 100644 --- a/server/events/runtime/run_step_runner_test.go +++ b/server/events/runtime/run_step_runner_test.go @@ -42,6 +42,10 @@ func TestRunStepRunner_Run(t *testing.T) { Command: "echo base_repo_name=$BASE_REPO_NAME base_repo_owner=$BASE_REPO_OWNER head_repo_name=$HEAD_REPO_NAME head_repo_owner=$HEAD_REPO_OWNER head_branch_name=$HEAD_BRANCH_NAME base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR", ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat base_branch_name=master pull_num=2 pull_author=acme\n", }, + { + Command: "echo user_name=$USER_NAME", + ExpOut: "user_name=acme-user\n", + }, } projVersion, err := version.NewVersion("v0.11.0") @@ -65,6 +69,9 @@ func TestRunStepRunner_Run(t *testing.T) { BaseBranch: "master", Author: "acme", }, + User: models.User{ + Username: "acme-user", + }, Log: logging.NewNoopLogger(), Workspace: "myworkspace", RepoRelDir: "mydir",