firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.05k stars 118 forks source link

avoid setting CI_PROJECT_ID #1168

Open justinTM opened 3 months ago

justinTM commented 3 months ago

https://github.com/firecow/gitlab-ci-local/blob/357299dde55c085b14443d3a678bdc32f510295e/src/predefined-variables.ts#L23

I am using CI_PROJECT_ID in scripts to curl the GitLab API, and it's always failing because 1217 is not correct, nor a valid id for any project.

in my curl scripts i am looking up the id by searching project names. otherwise i am setting CI_PROJECT_ID myself in other projects' dotenv files within my job.

either way, it doesn't seem wise to define a variable which will never be correct

i can imagine a scenario where a blank CI_PROJECT_ID might cause problems for people, maybe we can discuss a solution for this case? but ideally we would set it to the correct id based on the full path results from git remote origin? and if we're offline we can use cached previous results from a file in .gitlab-ci-local/ or make it blank, or something else

firecow commented 3 months ago

Yeah, it's probably best to just leave it undefined.

Options:
  --help                   Show help                                                                                                                                                                                                    
  --unset-variable         Unsets a variable (--unset-variable HELLO)             [array]

Use this one for now.

justinTM commented 3 months ago

sweet! thank you

alexey-vostrikov commented 1 month ago

It is better to set

  CI_SERVER_PROTOCOL: "https"
  CI_SERVER_PORT: "443"
  CI_SERVER_URL: "${CI_SERVER_PROTOCOL}://${CI_SERVER_HOST}:${CI_SERVER_PORT}"
  CI_API_V4_URL: "${CI_SERVER_URL}/api/v4"
  CI_JOB_TOKEN: glpat-XxXx(personal access token)

and get the project id from gitlab api

or even acquire CI_JOB_TOKEN via JWT? OAUTH2? another machanism?