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

Resolve BUILDKITE_COMMIT before pipeline upload #871

Merged
merged 1 commit into from
Dec 16, 2018
Merged
Changes from all 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
17 changes: 17 additions & 0 deletions clicommand/pipeline_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/buildkite/agent/logger"
"github.com/buildkite/agent/retry"
"github.com/buildkite/agent/stdin"
"github.com/buildkite/agent/env"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -169,8 +171,23 @@ var PipelineUploadCommand = cli.Command{
logger.Fatal("Config file is empty")
}

// Load environment to pass into parser
environ := env.FromSlice(os.Environ())

// resolve BUILDKITE_COMMIT based on the local git repo
if commitRef, ok := environ.Get(`BUILDKITE_COMMIT`); ok {
cmdOut, err := exec.Command(`git`, `rev-parse`, commitRef).Output()
if err != nil {
logger.Warn("Error running git rev-parse %q: %v", commitRef, err)
} else {
logger.Info("Updating BUILDKITE_COMMIT to %q", string(cmdOut))
environ.Set(`BUILDKITE_COMMIT`, string(cmdOut))
}
}

// Parse the pipeline
result, err := agent.PipelineParser{
Env: environ,
Filename: filename,
Pipeline: input,
NoInterpolation: cfg.NoInterpolation,
Expand Down