gitlab-ci-local icon indicating copy to clipboard operation
gitlab-ci-local copied to clipboard

Fetch CI_PROJECT_ID from gitlab instance

Open justinTM opened this issue 2 years ago • 7 comments

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

justinTM avatar Apr 01 '24 06:04 justinTM

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.

firecow avatar Apr 02 '24 06:04 firecow

sweet! thank you

justinTM avatar Apr 02 '24 06:04 justinTM

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?

alexey-vostrikov avatar Jun 14 '24 21:06 alexey-vostrikov

Wondering why the project ID is always set to 1217, wouldn't it be better to simply try to get the project ID at runtime then if the latter fails we simply keep it empty so the user can overwride it?

hkhelif avatar Aug 21 '24 07:08 hkhelif

@hkhelif

CI_PROJECT_ID is always set by gitlab, so we though it was best to assign it some sane value to avoid breaking stuff.

We will always default to 1217.

Are you guys having problems overriding it to your desired value?

firecow avatar Aug 21 '24 09:08 firecow

I have no problem to set it manually, but i want to set it automatically by making in API request in gitlab-ci-local internally

alexey-vostrikov avatar Aug 23 '24 12:08 alexey-vostrikov

Auto fetch CI_PROJECT_ID from public repositories., implement something using CI_JOB_TOKEN to fetch CI_PROJECT_ID from private repositories.

I've changed the title

firecow avatar Aug 24 '24 14:08 firecow