Skip to content

feat: add git config to templates

What does this MR do?

Long time ago while using the AutoDevOps templates we found out that our private packages couldn't be fetched, even if they were published inside GitLab.

This is a known issue in Go private modules and it gives the following error:

error: failed to list dependencies: failed to list modules: exit status 1
go list -m: gitlab.com/blockdaemon/nodestate-sdk/v2@v2.0.6-0.20220331132329-261dcd1ea441: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/19a406e9c45971fcbc2dc74ac589b53c75353b9ca91096fd715c62be5a7030e1: exit status 128:
	fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
go list -m: gitlab.com/blockdaemon/nodestate-sdk/v2@v2.0.6-0.20220331132329-261dcd1ea441: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/19a406e9c45971fcbc2dc74ac589b53c75353b9ca91096fd715c62be5a7030e1: exit status 128:
	fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled

The solution is quite simple, provide a token for authentication. [1] [2] [3]

git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf "https://gitlab.com/"

To my knowledge this change has no down side effects and my guess is that you would also face this issue if your modules aren't open source repositories.

It has the same effect as this option provided by GitLab's documentation with the upside of using the CI token instead of a user PAT. This is the official Git documentation on the config flag.

Alternatively, if not at the pipeline level, you can make that change at the runner level, as done here.

Checklist

Pre-merge

Consider the effect of the changes in this merge request on the following:

If new jobs are added:

This will help keep track of expected cost increases to the GitLab project average pipeline cost per merge request RPI

Post-merge

Edited by willian.eth

Merge request reports