Hi all -
I'm not a go (golang) developer, but the team that I support write their services in go. I need to build a pipeline for go builds. However... because of the strict pathing that go expects (/go/src/Y/Y/X), I'm having a hard time making a pipeline that works. My problem is that I need to run the build inside of a docker container and the host user is jenkins (501:501), so the docker user is 501, which can't write to "/" to create the necessary paths.
I've tried to set the GOPATH, but when I do it to the work space directory, it turns around and says that directory doesn't exist. It's baffling . So... if you have a working pipeline script for building go, I'd love for you to share it. Here's some examples of what I'm getting...
pipeline {
agent { docker 'golang:1.7.3-alpine' }
stages {
stage('build') {
steps {
sh 'env.GOPATH=$PWD'
sh 'mkdir -p $GOPATH/src/marketability-service'
dir('$GOPATH/src/marketability-service') {
sh 'go version'
sh 'echo $GOPATH'
sh 'mkdir -p $GOPATH/src/marketability-service/'
sh 'ls -al $GOPATH/src/marketability-service/'
checkout scm
sh 'ls -al'
}
}
}
}
}
Results:
+ docker pull golang:1.7.3-alpine
1.7.3-alpine: Pulling from library/golang
Digest: sha256:25ad25d8bece9d403be107b07c86fb6b2b588a5b26133baa9d1215c07bdbfa39
Status: Image is up to date for golang:1.7.3-alpine
[Pipeline] }
[Pipeline] // stage
[Pipeline] sh
[ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA] Running shell script
+ docker inspect -f . golang:1.7.3-alpine
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 501:501 -w /home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA -v /home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA:/home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA:rw -v /home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA@tmp:/home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat golang:1.7.3-alpine
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] sh
[ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA] Running shell script
+ env.GOPATH=/home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA
/home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA@tmp/durable-264541e0/script.sh: line 1: env.GOPATH=/home/jenkins/workspace/ity-service_tlester_jenkins-ZAK24AVEOSII6FI5ZPP6GCRQQ7ISJCROTD5BZVI3M4MT7EMS4ERA: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 141956393cfde63600f9fbb54475f50848279444b80abe647fef24c2bd9a5925
$ docker rm -f 141956393cfde63600f9fbb54475f50848279444b80abe647fef24c2bd9a5925
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
GitHub has been notified of this commit’s build result
ERROR: script returned exit code 127
Finished: FAILURE