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..
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.
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.
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.
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
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With