How can I allow "go get" or "go install" to pull from github inside a Jenkins Kubernetes pod executor?

1/16/2019

I am running Jenkins inside a Kubernetes cluster and setup to spawn an executor pod with 3 containers: jnlp, golang and kubectl.

Using "golang" container, I would like to be able to pull dependencies from github using "go install"

However, I am getting these errors (my code is in /go/src/test-app):

cannot find package "github.com/andreid/test-app/controllers" cannot find package "github.com/sirupsen/logrus"

and it seems unable to pull from github (though that's where Jenkins is pulling my code from and it's configured to do that using a developer oauth key that I generated).

It seems that the "jnlp" container handles the pulling of code successfully.

What can I do to allow "go install" to work as expected?

Thanks!

-- Andrei Dascalu
jenkins
kubernetes

1 Answer

1/21/2019

For posterity: when running Jenkins in a Kubernetes cluster with all the proper paraphernalia (Kubernetes pod agents, etc), there's no straightforward way to do this. You might expect agents will pick up github credentials setup in Jenkins, but they don't.

A quick way is to create a secret containing a github access token and mounting it as the env var GITHUB_TOKEN in the golang container used in the execution pod. YOu will need to maintain that secret or use multiple secrets if you have pipelines with multiple needs.

Then, you need to run:

git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/<myproject>".insteadOf "https://github.com/<myproject>" before doing build/get.

-- Andrei Dascalu
Source: StackOverflow