2016-05-16 20:27
浏览 267

Jenkins为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..

图片转代码服务由CSDN问答提供 功能建议

我们计划为Go项目设置Jenkin Build流程。 我在jenkins中设置了自定义工作区,并从“全局工具配置”中安装了go1.6。

我在执行 go build 时收到错误消息,下面是GOPATH 和GOROOT

  GOPATH / var / lib / jenkins / workspace / project / go 
GOROOT / var / lib / jenkins / workspace 
   \  n 
  ain.go:20:2:在以下任何位置都找不到包“ bytes”:
 / var / lib / jenkins / workspace / src / pkg / bytes  (来自$ GOROOT)
 / var / lib / jenkins / workspace / project / go / src / bytes(来自$ GOPATH)

我在这里缺少的内容 ?..谢谢您的帮助。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • duanjiao5082 2016-09-13 19:57

    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

    解决 无用
    打赏 举报
  • doulu2029 2016-05-16 20:56

    GOROOT should be the root of your go distribution. Normally you don't need to set it.

    Clear that and try again. If it still can't find bytes, set GOROOT to to directory where you installed go. Basically, this is the parent dir to wherever bin/go exists.

    解决 无用
    打赏 举报
  • duanguo7021 2016-05-17 10:46

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

    cd ${WORKROOT}
    # unzip go environment
    wget -c http://path/to/go/go1.6.2.linux-amd64.tar.gz
    tar -zxf $go_env
    if [ $? -ne 0 ];
        echo "fail in extract go"
        exit 1
    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 ];
        echo "fail to go build"
        exit 1
    echo "OK for go build"
    解决 无用
    打赏 举报
  • doubu7425 2017-08-16 21:12

    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

    解决 无用
    打赏 举报
  • dongye7231 2018-03-14 21:59

    I would recommend using Go Plugin for managing golang installations.

    Once you got it installed, it's important to understand golang environmental variables and their use, the mains are:

    $GOROOT specified the location where go is installed

    $GOPATH determines where your code is located and go get installs packages, by default it's ${HOME}/go

    withEnv(["GOROOT=${root}", "PATH+GO=${root}/bin:${HOME}/go/bin"]) {
        sh "go get"
        sh "gometalinter.v1 --help"

    With the setup above, we set GOROOT to our custom go installation and append $PATH with paths to binaries that we downloaded using go get and standard go

    解决 无用
    打赏 举报