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:
-
Different pipeline types - Non-canonical projects:
-
gitlab-foss
-
security
-
dev
-
personal forks
-
-
Pipeline performance
If new jobs are added:
-
Change-related rules (e.g. frontend/backend/database file changes): _____ -
Frequency they are running (MRs, main branch, nightly, bi-hourly): _____ -
Add a duration chart to https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations if there are new jobs added to merge request pipelines
This will help keep track of expected cost increases to the GitLab project average pipeline cost per merge request RPI
Post-merge
-
Consider communicating these changes to the broader team following the communication guideline for pipeline changes