2021-10-14 14:41:58 +02:00
# Azure Pipelines
2022-09-17 00:13:09 -03:00
GoReleaser can also be used within our official [GoReleaser Extensions for Azure
DevOps][goreleaser-extension] through [Visual Studio marketplace][marketplace].
2021-11-05 14:47:06 +01:00
### Task definition
2024-11-29 01:32:13 -03:00
```yaml
2021-11-05 14:47:06 +01:00
- task: goreleaser@0
inputs:
2024-11-29 01:32:13 -03:00
version: "latest"
distribution: "goreleaser"
args: ""
workdir: "$(Build.SourcesDirectory)"
```
2021-11-05 14:47:06 +01:00
### Task inputs
2022-09-17 00:13:09 -03:00
Following inputs can be used:
2021-11-05 14:47:06 +01:00
2022-09-17 00:13:09 -03:00
<!-- to format the tables, use: https://tabletomarkdown.com/format - markdown - table/ -->
2021-11-05 14:47:06 +01:00
2024-11-29 01:32:13 -03:00
| Name | Type | Default | Description |
| ------------------- | ------ | --------------------------- | ---------------------------------------------------------------- |
| `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` |
| `version` [^version] | String | `latest` | GoReleaser version |
| `args` | String | | Arguments to pass to GoReleaser |
| `workdir` | String | `$(Build.SourcesDirectory)` | Working directory (below repository root) |
| `installOnly` | Bool | `false` | Just install GoReleaser |
2022-08-16 01:33:27 -03:00
2024-11-29 01:32:13 -03:00
[^version]:
Can be a fixed version like `v1.10.0` or a max satisfying semver one
like `~> v1.10` . In this case this will return the latest patch release of
`v1.10` . For the `pro` version, add `-pro` to the string
2021-11-05 14:47:06 +01:00
### Task environment variables
```yaml
2024-11-29 01:32:13 -03:00
---
variables:
- name: GORELEASER_KEY
value: xxx
---
2021-11-05 14:47:06 +01:00
or short:
2024-11-29 01:32:13 -03:00
---
2021-11-05 14:47:06 +01:00
variables:
GORELEASER_KEY: xxx
```
Following environment variables can be used, as environment variable.
2024-11-29 01:32:13 -03:00
| Name | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `GITHUB_TOKEN` | [GITHUB_TOKEN ](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token ) for e.g. `brew` |
| `GORELEASER_KEY` | Your [GoReleaser Pro ](https://goreleaser.com/pro ) License Key, in case you are using the `goreleaser-pro` distribution |
2021-11-05 14:47:06 +01:00
### Example pipeline
Generally there are two ways to define an [Azure Pipeline ](https://azure.microsoft.com/en-us/services/devops/pipelines/ ):
2021-10-14 14:41:58 +02:00
Classic pipelines defined in the UI or YAML pipelines.
Here is how to do it with YAML:
```yaml
# customize trigger to your needs
trigger:
branches:
include:
- main
- refs/tags/*
variables:
2023-02-05 13:39:39 -03:00
GO_VERSION: "1.20"
2021-10-14 14:41:58 +02:00
pool:
vmImage: ubuntu-latest
jobs:
- job: Test
steps:
- task: GoTool@0
inputs:
version: "$(GO_VERSION)"
displayName: Install Go
- bash: go test ./...
displayName: Run Go Tests
- job: Release
# only runs if Test was successful
dependsOn: Test
# only runs if pipeline was triggered from a branch.
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags'))
steps:
- task: GoTool@0
inputs:
version: "$(GO_VERSION)"
displayName: Install Go
2021-11-05 14:47:06 +01:00
- task: goreleaser@0
inputs:
2024-11-29 01:32:13 -03:00
version: "latest"
distribution: "goreleaser"
args: ""
workdir: "$(Build.SourcesDirectory)"
2021-10-14 14:41:58 +02:00
```
2021-11-05 14:47:06 +01:00
In this example a `Test` job is used to run `go test ./...` to first make sure that there're no failing tests. Only if
2023-04-30 00:02:38 +00:00
that job succeeds and the pipeline was triggered from a tag (because of the defined `condition` ) GoReleaser will be run.
2021-11-05 14:47:06 +01:00
[goreleaser-extension]: https://marketplace.visualstudio.com/items?itemName=GoReleaser.goreleaser
[marketplace]: https://marketplace.visualstudio.com/azuredevops