在基于Docker的Jenkins代理中找不到Go

I have created a Docker-based Jenkins agent that uses docker:stable-dind (which is based on Alpine 3.10) as its base. Full Dockerfile.

In the Dockerfile I install Go: RUN apk add go

When running locally, e.g. go version, go env GOROOT, etc... I get results, e.g. 1.12.6, /usr/lib/go.

I then attempt using this agent in Jenkins, and print env to verify the above environment variables are, but they not there and also go version fails`.

So, I update the Docker agent template in Jenkins with:

  • GOROOT: /usr/lib/go
  • PATH:/bin/sonar-scanner/bin/:/usr/local/bin:$GOROOT/bin:$PATH

Now when checking env they are there...

GOROOT=/usr/lib/go
PATH=/bin/sonar-scanner/bin/:/usr/local/bin:/usr/lib/go/bin:/bin:/usr/bin:/sbin:/usr/sbin
GOPATH=/home/jenkins/workspace/go test

... but go version still fails.

GOPATH is set to the current $WORKSPACE as that's where I will clone the Go project source if this actually works.

This is the Jenkins job:

#!groovy

pipeline {
  agent {
    label 'cli-agent'
  }

  stages {
    stage ("test") {
      steps {
        script {
          withEnv(["GOPATH=${WORKSPACE}"]) {
             sh """
                env
                go version
             """
          }
        }
      }
    }
  }
}