drvpv7995 2019-08-04 16:25 采纳率: 100%
浏览 264

在基于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
             """
          }
        }
      }
    }
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试