title: Go not found in Docker-based Jenkins agent
body: <p>I have created a Docker-based Jenkins agent that uses <code>docker:stable-dind</code> (which is based on Alpine 3.10) as its base. <a href="https://pastebin.com/mw6HQEV5" rel="nofollow noreferrer">Full Dockerfile</a>.</p>
  
  <p>In the Dockerfile I install Go: <code>RUN apk add go</code></p>
  
  <p>When running locally, e.g. <code>go version</code>, <code>go env GOROOT</code>, etc... I get results, e.g. <code>1.12.6</code>, <code>/usr/lib/go</code>.</p>
  
  <p>I then attempt using this agent in Jenkins, and print <code>env</code> to verify the above environment variables are, but they not there and also <code>go version</code> fails`.</p>
  
  <p>So, I update the Docker agent template in Jenkins with:</p>
  
  <ul>
  <li><code>GOROOT</code>: <code>/usr/lib/go</code></li>
  <li><code>PATH</code>:<code>/bin/sonar-scanner/bin/:/usr/local/bin:$GOROOT/bin:$PATH</code></li>
  </ul>
  
  <p>Now when checking <code>env</code> they are there...</p>
  
  <pre><code>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
  </code></pre>
  
  <p>... but <code>go version</code> still fails.</p>
  
  <p><code>GOPATH</code> is set to the current <code>$WORKSPACE</code> as that's where I will clone the Go project source if this actually works.</p>
  
  <p>This is the Jenkins job: </p>
  
  <pre><code>#!groovy
  
  pipeline {
    agent {
      label 'cli-agent'
    }
  
    stages {
      stage ("test") {
        steps {
          script {
            withEnv(["GOPATH=${WORKSPACE}"]) {
               sh """
                  env
                  go version
               """
            }
          }
        }
      }
    }
  }
  </code></pre>