Skip to content

Commit

Permalink
Add CommentArgs to run step runner (#693)
Browse files Browse the repository at this point in the history
Add CommentArgs to run step runner

This should allow the extra args passed in the comment to be used by
run steps

Fixes #670
  • Loading branch information
rowleyaj authored and lkysow committed Jul 11, 2019
1 parent 595e1d4 commit dd02dea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions runatlantis.io/docs/custom-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions server/events/runtime/run_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

version "github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/models"
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions server/events/runtime/run_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit dd02dea

Please sign in to comment.