Good read — please note that if you have a properly set up GitLab instance, then your registry is available under this variable:
If you ever need to reference this job, you can make use of
$CI_JOB_ID (should be unique per job) or in the case of the project
$CI_PROJECT_ID if you rather have a static reference.
I usually need to deploy an image from the private registry to a public one so that’s usually a variable I define under secret variables as you mentioned (note that I would rather like to have global variables or per-user variables since the registry is public).
But for now I could simply write something like the following to set my variables:
But that can be improved with:
While not much changed, it does make it portable (there goes a snippet to share). Note that
$PUB_REGISTRY requires that secret variable to be set. Additionally,
$CI_COMMIT_REF_NAME takes care of picking the branch name.
I’m still learning GitLab so I keep this in one of my tabs at the moment.