Skip to content

Go build tags

Go build tags (or build constraints) are conditional compilation directives used to control which source files are included in a Go package build^[400-devops__04-CI-CD-Pipelines__drone.md].

They are specified using the -tags flag during the go build command^[400-devops__04-CI-CD-Pipelines__drone.md]. This mechanism allows developers to tailor the build process by excluding or including specific code blocks based on the tags provided^[400-devops__04-CI-CD-Pipelines__drone.md].

Usage

To apply build tags, the flag is passed directly to the build command^[400-devops__04-CI-CD-Pipelines__drone.md].

Syntax:

go build -tags "tag1, tag2" import/path

For example, to build a specific version of the Drone CI server with restrictions removed, the command is:

go build -tags "nolimit" github.com/drone/drone/cmd/drone-server
^[400-devops__04-CI-CD-Pipelines__drone.md]

Multiple tags can be combined to satisfy complex requirements. The following command includes both the oss and nolimit tags:

go build -tags "oss nolimit" github.com/drone/drone/cmd/drone-server
^[400-devops__04-CI-CD-Pipelines__drone.md]

Sources

  • 400-devops__04-CI-CD-Pipelines__drone.md