在Jenkins中构建带有私有存储库中的依赖项的go项目

I'm trying to set up automated build for go projects. Most people just use github dependencies which don't need credentials. We have some internal dependencies however available on our private git central server. Credentials are needed however to have go access these.

A possible workaround would be to configure a global git variable inside our build machines / build dockers; something like:

git config --global url."https://user:password@private.git.server/".insteadOf "https://private.git.server/"

however this doesn't seem to be the best solution to me, since the password would be stored in a human-readable text file.

I think the git-credentials plugin should be able to help me out; could I maybe export GIT_TERMINAL_PROMPT=1 and let the git-credentials plugin fill in for me?

How could I make sure go get or go install gets access to our private repository in a secure way?

I use a workaround with GITHUB_TOKEN to solve this.

  1. Generate GITHUB_TOKEN here https://github.com/settings/tokens
  2. export GITHUB_TOKEN=xxx
  3. git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/mycompany".insteadOf "https://github.com/mycompany"

This way you don't expose the password and can revoke token at any time.

Note: Go uses http when downloading dependencies, not ssh.