-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buildkite-agent env has --from-env-file (bool) and --print NAME flags
This solves the problem of safely parsing BUILDKITE_ENV_FILE, and allows for usage like this in a pre-command hook or similar: local branch branch="$(buildkite-agent env --from-env-file --print BUILDKITE_BRANCH)" if [[ branch != "main" ]]; then echo "This agent only builds branch 'main'" exit 42 fi
- Loading branch information
Showing
2 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package clicommand | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMustLoadEnvFile(t *testing.T) { | ||
f, err := os.CreateTemp("", t.Name()) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
data := map[string]string{ | ||
"HELLO": "world", | ||
"FOO": "bar\n\"bar\"\n`black hat`\r\n$(have you any root)", | ||
} | ||
for name, value := range data { | ||
fmt.Fprintf(f, "%s=%q\n", name, value) | ||
} | ||
|
||
result := mustLoadEnvFile(f.Name()) | ||
|
||
assert.Equal(t, data, result, "data should round-trip via env file") | ||
} |