0

I need to make a Gitlab API REST call (let's say "GET /projects/:id/jobs/:job_id") from a script running during CI pipelines' job execution. I need a token to pass through security check. Sure I can create such a token (PAT) and to use it and it works fine. But how can I save/pass this token to the pipeline? To hard-code it in the Gitlab CI YAML file? To hard-code it directly in the script? What is the correct solution here?

I read here that Gitlab itself provides such a token directly in the job. Previously it was stored in the CI_JOB_TOKEN environment variable. I tried it, but I get HTTP 401 error, and it seems its string value is "[MASKED]". How to achieve it - to do REST call with a token during job execution in convenient way? Any example, hints will be very helpful.

EDIT: I found this post on Reddit. It seems the way is PAT only (separate per project) ?

RandomB
  • 3,367
  • 19
  • 30

1 Answers1

1

But how can I save/pass this token to the pipeline? To hard-code it in the Gitlab CI YAML file? To hard-code it directly in the script? What is the correct solution here?

Just inject it via environment variable: Settings -> CI/CD -> Variables

makozaki
  • 3,772
  • 4
  • 23
  • 47