2021-10-30 09:50:23 -03:00
|
|
|
# Environment Variables
|
2019-03-03 14:12:22 -03:00
|
|
|
|
|
|
|
Global environment variables to be passed down to all hooks and builds.
|
|
|
|
|
2022-09-17 00:13:09 -03:00
|
|
|
If you have an environment variable named `FOOBAR` set to `on`, your
|
|
|
|
`.goreleaser.yaml` file could use it like this:
|
2019-03-03 14:12:22 -03:00
|
|
|
|
|
|
|
```yaml
|
2021-12-23 01:52:01 +01:00
|
|
|
# .goreleaser.yaml
|
2019-03-03 14:12:22 -03:00
|
|
|
env:
|
2021-05-31 01:53:57 +00:00
|
|
|
- FOO={{ .Env.FOOBAR }}
|
|
|
|
- ENV_WITH_DEFAULT={{ if index .Env "ENV_WITH_DEFAULT" }}{{ .Env.ENV_WITH_DEFAULT }}{{ else }}default_value{{ end }}
|
2019-03-03 14:12:22 -03:00
|
|
|
before:
|
|
|
|
hooks:
|
2021-03-02 21:29:31 -03:00
|
|
|
- go mod tidy
|
2019-03-03 14:12:22 -03:00
|
|
|
builds:
|
|
|
|
- binary: program
|
|
|
|
```
|
|
|
|
|
2022-09-17 00:13:09 -03:00
|
|
|
This way, both your before hooks (in this example, `go mod tidy`) and the
|
|
|
|
underlying builds (using `go build`) will have `FOO` set to `on`.
|
2019-03-03 14:12:22 -03:00
|
|
|
|
2021-05-24 23:23:59 -03:00
|
|
|
The root `env` section also accepts templates.
|
|
|
|
|
|
|
|
!!! tip
|
|
|
|
Learn more about the [name template engine](/customization/templates/).
|