Go programming language plugin for Jenkins
Automatically installs and sets up the Go programming language (golang) tools on a Jenkins agent during a build.
Functionality
During a build, this plugin can:
- Install a particular version of Go on the agent that the build is running on
- The correct package for the machine's operating system and CPU architecture will be automatically downloaded and installed, if not already present
- Export the
GOROOT
environment variable, pointing to the installed Go tools - Add the path
$GOROOT/bin
to thePATH
, so that the tools are available during the build
Usage
Global configuration
- In the Jenkins global tool configuration settings (Manage Jenkins → Global Tool Configuration), find the "Go" section, click "Go Installations…" and "Add Go".
- Enter a name, e.g. "Go 1.15" — the name itself has no significance, but will be displayed to users during Freestyle job configuration, or is what you need to enter as the
name
in a Pipeline - Either select "Install automatically" and select the desired Go version from the drop-down list or specify the installation directory manually
Per-job configuration
Freestyle
- In a job's configuration, find the "Build environment" section
- Select the "Set up Go programming language tools" checkbox
- Select the name of a Go installation from the drop-down
Pipeline
As with any other type of Tool Installer, you can use the tool
step, in this case with the go
tool type.
For example, with a Scripted Pipeline:
// Run on an agent where we want to use Go
node {
// Ensure the desired Go version is installed
def root = tool type: 'go', name: 'Go 1.15'
// Export environment variables pointing to the directory where Go was installed
withEnv(["GOROOT=${root}", "PATH+GO=${root}/bin"]) {
sh 'go version'
}
}
Changelog
See CHANGELOG.md.