i have a gitlab project and learning how to use the gitlab api , to run a specific job. based on the documentation for gitlab api , i can trigger a particular job via gitlab api, so , first i tried to get all the jobs with job id for a particular project.
curl -X GET -F token=********** -F ref=main https://gitlab.example.com/api/v4/projects/project_id/jobs
I'm getting {message: 401 unauthoried} for this, I'm owner of the project but i still get unauthorized . what permissions do i need to configure , to successfully make this call.
Note - however , if i try to trigger the pipeline for the same project , i don't get unauthorized. the command i use for this is
curl --request POST "https://gitlab.example.com/api/v4/projects/project_id/trigger/pipeline?token=**********&ref=main
sample .gitlab-ci.yml file
build-job:
stage: build
script:
- echo "Hello, $GITLAB_USER_LOGIN!"
test-job1:
stage: test
script:
- python3 myproject/script/mydumbscript.py $arg1 $arg2 $arg3
test-job2:
stage: test
script:
- echo "This job tests something, but takes more time than test-job1."
- echo "After the echo commands complete, it runs the sleep command for 20 seconds"
- echo "which simulates a test that runs 20 seconds longer than test-job1"
- sleep 20
deploy-prod:
stage: deploy
script:
- echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
environment: production