Automatically installs and sets up the Go programming language (golang) tools on a Jenkins agent during a build.
During a build, this plugin can:
GOROOT
environment variable, pointing to the installed Go tools$GOROOT/bin
as a prefix of the PATH
, so that the tools are available during the buildOnce this plugin is installed, you must first configure which Go version(s) you need for your Jenkins jobs, and then configure any jobs that need Go as appropriate.
You can use the tools
directive within any pipeline
or stage
. For example:
pipeline {
// Run on an agent where we want to use Go
agent any
// Ensure the desired Go version is installed for all stages,
// using the name defined in the Global Tool Configuration
tools { go '1.19' }
stages {
stage('Build') {
steps {
// Output will be something like "go version go1.19 darwin/arm64"
sh 'go version'
}
}
}
}
You will need to grab the installation directory from the tool
step, and ensure that the correct GOROOT
and PATH
are set. For example:
// Run on an agent where we want to use Go
node {
// Ensure the desired Go version is installed on this agent,
// using the name defined in the Global Tool Configuration
def root = tool type: 'go', name: '1.19'
// Export environment variables to pointing the Go installation;
// the `PATH+X` syntax prepends an item to the existing `PATH`:
// https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables
withEnv(["GOROOT=${root}", "PATH+GO=${root}/bin"]) {
// Output will be something like "go version go1.19 darwin/arm64"
sh 'go version'
}
}
See CHANGELOG.md.