Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins build setup for Go Projects

We are planning to setup Jenkin Build process for Go Projects. I setup Custom Workspace in jenkins and installing go1.6 from "Global Tool Configuration".

I am getting error message while executing go build Below is the GOPATH and GOROOT

GOPATH /var/lib/jenkins/workspace/project/go
GOROOT  /var/lib/jenkins/workspace

ain.go:20:2: cannot find package "bytes" in any of:
    /var/lib/jenkins/workspace/src/pkg/bytes (from $GOROOT)
    /var/lib/jenkins/workspace/project/go/src/bytes (from $GOPATH)

What I am missing here?.. Thanks for your help..

like image 461
rameshthoomu Avatar asked May 16 '16 20:05

rameshthoomu


People also ask

Does Jenkins support Golang?

After the plugins have been installed, you can use Jenkins to develop them further. This lets the Jenkins node know that Docker and Golang are available inside the plugin. Next, you need to configure these plugins globally by going to Manage Jenkins -> Global Tool Configuration.

How do you build a Multibranch pipeline in Jenkins?

Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.

How does Jenkins Multibranch pipeline work?

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.


3 Answers

In addition to letting the Go plugin handle your GOROOT, there are some nuances to the GOPATH as well when it comes to getting dependencies. We are putting our *.go source files in the root of our Git repositories, so they are easily managed via go commands on the Dev desktops. So, I am using a build script to trick Go into thinking there is a package called main under /src/main via a symlink so that I can use the same script to build all of my go packages and pull the dependencies. Here is my build script:

#!/usr/bin/bash export GOPATH=$WORKSPACE mkdir -p $GOPATH/src ln -f -s $WORKSPACE $GOPATH/src/main go get main CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main main

like image 193
CameronGo Avatar answered Nov 15 '22 07:11

CameronGo


I use jenkin too but write build.sh by myself. To give you a reference:

build.sh

#!/usr/bin/bash

WORKROOT=$(pwd)
cd ${WORKROOT}

# unzip go environment
go_env="go1.6.2.linux-amd64.tar.gz"
wget -c http://path/to/go/go1.6.2.linux-amd64.tar.gz
tar -zxf $go_env
if [ $? -ne 0 ];
then
    echo "fail in extract go"
    exit 1
fi
echo "OK for extract go"
rm -rf $go_env

# prepare PATH, GOROOT and GOPATH
export PATH=$(pwd)/go/bin:$PATH
export GOROOT=$(pwd)/go
export GOPATH=$(pwd)

# build
cd path/to/your/project
go build
if [ $? -ne 0 ];
then
    echo "fail to go build"
    exit 1
fi
echo "OK for go build"
like image 45
leiyonglin Avatar answered Nov 15 '22 06:11

leiyonglin


because jenkins works very well with maven. you can build golang projects under jenkins with mvn-golang plugin and also make reports compatible with jenkins

like image 44
Igor Maznitsa Avatar answered Nov 15 '22 07:11

Igor Maznitsa