Access GitLab Resources in GitLab Runner Jobs
In complex CI/CD scenarios, we may need to access other resources from GitLab that is out of current project/repository, like cloning another repository, or calling gitlab API to trigger a contiguous job.
These resources are accessible via CI/CD job token.
Clone a Repository Using CIJOBTOKEN
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.example.com/<namespace>/<project>
Trigger a Job Using CIJOBTOKEN
curl --request POST --form token=${CI_JOB_TOKEN} https://gitlab.example.com/api/v4/projects/<project_id>/trigger/pipeline