Building Golang Projects on Jenkins DEV@cloud

Written by: Michael Neale

I have had a few questions on if it is possible to use Google Go on DEV@cloud when building - as it is isn't obviously baked in.

Well you can, and it is easy. Create a freestyle job.

Download direct option:

The script I use is:

go_version=go1.2.2.linux-amd64

if [ ! -e $go_version.tar.gz ]
then
wget https://storage.googleapis.com/golang/$go_version.tar.gz
tar xf $go_version.tar.gz
fi

export GOROOT=$WORKSPACE/go
export PATH=$PATH:$GOROOT/bin

go version
go get
go test
...

This downloads the Go binary, if it isn't already in the workspace (workspaces are cached, so most of the time it won't have to do what is in the "if" block).

Once it is installed, the GOROOT and PATH are set - and away you, um... Go ;)

Go is one of the easiest things to install in the world (and the binaries it produces are statically linked so also easy to use).

This one uses the latest version of Go at the time of writing.

The script is also here .

Use GVM option

The gvm script lets you select the version of go you want - and installs the version of go as needed.

The script to enable this:

if [ ! -e /home/jenkins/.gvm/scripts/gvm ]

then

wget https://raw.githubusercontent.com/moovweb/gvm/controller/binscripts/gvm-installer

chmod +x gvm-installer

./gvm-installer

fi

source /home/jenkins/.gvm/scripts/gvm

gvm install go1

gvm use go1 [--default]

You can also download the script from here .

@michaelneale

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.