Building Go app with “vendor” directory on Jenkins with Docker

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:

  • Install Oracle on docker centos container: Insufficient disk space
  • How to visit another host inside docker?
  • Attaching process to Docker libcontainer container
  • Connection issue with Jenkins within Docker on RaspberryPi 3 (rpi-jenkins) when cloning a Bitbucket Git Repo
  • Docker SSH or Detach/Attach
  • Profiling Java application in kubernetes
  • + goapp test ./...
    src/dao/demo_dao.go:8:2: cannot find package "" in any of:
        /usr/lib/go_appengine/goroot/src/ (from $GOROOT)
        /usr/lib/go_appengine/gopath/src/ (from $GOPATH)

    …why isn’t it picking up the Vendor directory?

    When I throw in some logging, it seems that after running sh "cd /workspace/src/" 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/") {} 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 -q -O && \
        unzip -q -d /usr/lib/ && \
    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()
                    "-v ${env.WORKSPACE}:/workspace/src/ " +
                    "-e GOPATH=/usr/lib/go_appengine/gopath:/workspace") {
                // Debugging
                sh 'echo GOPATH: $GOPATH'
                sh "ls -al /workspace/src/"
                sh "cd /workspace/src/"
                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

  • Running docker container : iptables: No chain/target/match by that name
  • Issue regarding the Dockerfile creation
  • Contents in the container's bind-mounted dir keep unchanged after mounting/umounting removable drive from the host
  • Authorization error with AWS
  • Docker, aufs, and unattended-upgrades
  • Docker images across multiple disks
  • One Solution collect form web for “Building Go app with “vendor” directory on Jenkins with Docker”

    I managed to get it working by including the cd in the same sh statement:

          .inside("-v ${env.WORKSPACE}:/workspace/src/ " +
                  "-e GOPATH=/usr/lib/go_appengine/gopath:/workspace") {
       sh """
           cd /workspace/src/
           go vet ./src/...
           goapp test ./...
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.