dounaoji2054 2016-08-17 11:54
浏览 84
已采纳

使用Docker在Jenkins上使用“供应商”目录构建Go应用

I'm trying to set up a Jenkins Pipeline to build and deploy my first Go project using a Jenkinsfile and docker.image().inside . I can't figure out how to get go to pick up the dependencies in the vendor/ directory.

When I run the build, I get a bunch of errors:

+ goapp test ./...
src/dao/demo_dao.go:8:2: cannot find package "github.com/dgrijalva/jwt-go" in any of:
    /usr/lib/go_appengine/goroot/src/github.com/dgrijalva/jwt-go (from $GOROOT)
    /usr/lib/go_appengine/gopath/src/github.com/dgrijalva/jwt-go (from $GOPATH)
    /workspace/src/github.com/dgrijalva/jwt-go

...why isn't it picking up the Vendor directory?

When I throw in some logging, it seems that after running sh "cd /workspace/src/bitbucket.org/nalbion/go-demo" the next sh command is still in the original ${WORKSPACE} directory. I really like the idea of the Jenkins file, but I can't find any decent documentation for it.

(Edit - there is decent documentation here but dir("/workspace/src/bitbucket.org/nalbion/go-demo") {} doesn't seem to work within docker.image().inside)

My Docker file resembles:

FROM golang:1.6.2
# Google's App Engine Go SDK
RUN wget https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.40.zip -q -O go_appengine_sdk.zip && \
    unzip -q go_appengine_sdk.zip -d /usr/lib/ && \
    rm go_appengine_sdk.zip
ENV PATH /usr/lib/go_appengine:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV GOPATH /usr/lib/go_appengine/gopath
# Add Jenkins user
RUN groupadd -g 132 jenkins && useradd -d "/var/jenkins_home" -u 122 -g 132 -m -s /bin/bash jenkins

And my Jenkinsfile:

node('docker') {
    currentBuild.result = "SUCCESS"

    try {
        stage 'Checkout'
        checkout scm

        stage 'Build and Test'
        env.WORKSPACE = pwd()
        docker.image('nalbion/go-web-build:latest').inside(
                "-v ${env.WORKSPACE}:/workspace/src/bitbucket.org/nalbion/go-demo " +
                "-e GOPATH=/usr/lib/go_appengine/gopath:/workspace") {

            // Debugging
            sh 'echo GOPATH: $GOPATH'
            sh "ls -al /workspace/src/bitbucket.org/nalbion/go-demo"
            sh "cd /workspace/src/bitbucket.org/nalbion/go-demo"
            sh "pwd"

            sh "go vet ./src/..."
            sh "goapp test ./..."
        }

        stage 'Deploy to DEV'
        docker.image('nalbion/go-web-build').inside {
            sh "goapp deploy --application go-demo --version v${v} app.yaml"
        }

        timeout(time:5, unit:'DAYS') {
            input message:'Approve deployment?', submitter: 'qa'
        }

        stage 'Deploy to PROD'
        docker.image('nalbion/go-web-build').inside {
            sh "goapp deploy --application go-demo --version v${v} app.yaml"
        }
    } catch (err) {
        currentBuild.result = "FAILURE"
        // send notifications
        throw err
    }
}
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 VB6.0操作 webview2内核的浏览器如何精确实现网页弹窗处置
      • ¥15 pr导出的视频打不开,提示“缺少编解码器”怎么解决
      • ¥15 html里js获取php参数值不成功,帮改代码
      • ¥20 如何控制ant design的InputNumber组件 最多输入5位小数
      • ¥15 c语言学生基本信息管理系统
      • ¥100 火车头采集器采集求解
      • ¥88 关于#运行时间 时间重叠 和非重叠#的问题,如何解决?
      • ¥15 C语言,密切接触者追踪
      • ¥20 关于计算机网络问题,请附带讲解
      • ¥30 自动识别图像目标并判断