From dd02deaf76afd4a756c0dadf923864fd17575488 Mon Sep 17 00:00:00 2001 From: Alex Rowley Date: Thu, 11 Jul 2019 14:21:36 +0100 Subject: [PATCH] Add CommentArgs to run step runner (#693) Add CommentArgs to run step runner This should allow the extra args passed in the comment to be used by run steps Fixes #670 --- runatlantis.io/docs/custom-workflows.md | 1 + server/events/runtime/run_step_runner.go | 2 ++ server/events/runtime/run_step_runner_test.go | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/runatlantis.io/docs/custom-workflows.md b/runatlantis.io/docs/custom-workflows.md index b92ed0427a..ce3a77bf87 100644 --- a/runatlantis.io/docs/custom-workflows.md +++ b/runatlantis.io/docs/custom-workflows.md @@ -322,6 +322,7 @@ Or a custom command * `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`. + * `COMMENT_ARGS` - Any additional flags passed in the comment on the pull request separated by commas, ex. `atlantis plan -- arg1 arg2` will result in `COMMENT_ARGS=arg1,arg2`. * A custom command will only terminate if all output file descriptors are closed. Therefore a custom command can only be sent to the background (e.g. for an SSH tunnel during the terraform run) when its output is redirected to a different location. For example, Atlantis diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index f7a7cb2fce..54ab6a805d 100644 --- a/server/events/runtime/run_step_runner.go +++ b/server/events/runtime/run_step_runner.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" version "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/models" @@ -28,6 +29,7 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, pa "BASE_BRANCH_NAME": ctx.Pull.BaseBranch, "BASE_REPO_NAME": ctx.BaseRepo.Name, "BASE_REPO_OWNER": ctx.BaseRepo.Owner, + "COMMENT_ARGS": strings.Join(ctx.CommentArgs, ","), "DIR": path, "HEAD_BRANCH_NAME": ctx.Pull.HeadBranch, "HEAD_REPO_NAME": ctx.HeadRepo.Name, diff --git a/server/events/runtime/run_step_runner_test.go b/server/events/runtime/run_step_runner_test.go index d12dc7cc8e..32f6207a77 100644 --- a/server/events/runtime/run_step_runner_test.go +++ b/server/events/runtime/run_step_runner_test.go @@ -63,6 +63,10 @@ func TestRunStepRunner_Run(t *testing.T) { Command: "echo user_name=$USER_NAME", ExpOut: "user_name=acme-user\n", }, + { + Command: "echo args=$COMMENT_ARGS", + ExpOut: "args=-target=resource1,-target=resource2\n", + }, } projVersion, err := version.NewVersion("v0.11.0") @@ -98,6 +102,7 @@ func TestRunStepRunner_Run(t *testing.T) { RepoRelDir: "mydir", TerraformVersion: projVersion, ProjectName: c.ProjectName, + CommentArgs: []string{"-target=resource1", "-target=resource2"}, } out, err := r.Run(ctx, c.Command, tmpDir) if c.ExpErr != "" {