Fetch raw job output from pipeline API in BASH

Hey GitLab mates,

for a current project we looking to fetch pipeline jobs from the API.
Scope is to do all that within BASH scripts using cURL for querying.
So far we’re already getting out those fruits from beloved GitLab API:

pipeline_id=$(curl --header "PRIVATE-TOKEN: $GITLAB_PASSWORD" --silent "https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/repository/commits/${branch}" | jq '.last_pipeline.id')
ci_output=$(curl --header "PRIVATE-TOKEN: $GITLAB_PASSWORD" --silent "https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/pipelines/${pipeline_id}")

But we’re don’t grasp how to fetch all jobs run by a certain pipeline.
RTFM didn’t help us here https://docs.gitlab.com/ce/api/pipelines.html
The idea is to fetch somehow all the jobs IDs via something like:

https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/-/pipelines/${pipeline_id}/builds

For then looping over all those jobs IDs to get their output via:

https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/-/jobs/${GITLAB_JOB_ID/raw

Would be wonderful if someone could help us here how to access that :smiley:

Can’t you use List pipeline jobs API?

GET /projects/:id/pipelines/:pipeline_id/jobs

2 Likes

Thanks bro that tip was awesome! :metal: RTFM after all and here is the BASH:

ci_jobs=$(curl --header "PRIVATE-TOKEN: $GITLAB_PASSWORD" --silent "https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/pipelines/${pipeline_id}/jobs" | jq '.[].id')
for JOB_ID in $ci_jobs; do curl --header "PRIVATE-TOKEN: $GITLAB_PASSWORD" --silent "https://${GITLAB_HOSTNAME}/api/v4/projects/${GITLAB_PROJECT_ID}/jobs/${JOB_ID}/trace"; done

FYI end result is an improved GitHub action for GitLab CI: