Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch CI_PROJECT_ID from gitlab instance #1168

Open
justinTM opened this issue Apr 1, 2024 · 7 comments
Open

Fetch CI_PROJECT_ID from gitlab instance #1168

justinTM opened this issue Apr 1, 2024 · 7 comments
Labels
feature Feature missing according to gitlab ci standard

Comments

@justinTM
Copy link

justinTM commented Apr 1, 2024

CI_PROJECT_ID: "1217",

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
Copy link
Owner

firecow commented Apr 2, 2024

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
Copy link
Author

justinTM commented Apr 2, 2024

sweet! thank you

@firecow firecow added the feature Feature missing according to gitlab ci standard label Apr 10, 2024
@alexey-vostrikov
Copy link

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?

@hkhelif
Copy link

hkhelif commented Aug 21, 2024

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?

@firecow
Copy link
Owner

firecow commented Aug 21, 2024

@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?

@alexey-vostrikov
Copy link

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

@firecow
Copy link
Owner

firecow commented Aug 24, 2024

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 firecow changed the title avoid setting CI_PROJECT_ID Fetch CI_PROJECT_ID from gitlab instance Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature missing according to gitlab ci standard
Projects
None yet
Development

No branches or pull requests

4 participants