Good day, was wondering how I’d go about doing this with the API? I have my pipelines creating artifacts but each successive build has an incrementing ID. For example:
I want to grab the latest project-manual-####.pdf from another projects builder but how to handle the unknown pipeline ID. I want the latest one so would something like this work? I tried it and get a 404 File Not Found error.
Appreciate any tips / help, thank you
I understand you’re trying to fetch the latest artifact file without knowing the pipeline ID. You’re on the right track, but there’s a bit more to it. Let’s break it down:
Get the latest pipeline for a specific branch: You can use the GitLab Pipelines API to fetch the latest pipeline for a specific branch. Here’s an example API call:
This will return a list of pipelines for the
main branch, ordered by ID in descending order. The first pipeline in the response will be the latest one. You can find more details in the Pipelines API documentation.
Get the latest job in the pipeline: Once you have the pipeline ID, you can use the Jobs API to fetch the jobs for that pipeline. Here’s an example API call:
This will return a list of successful jobs for the given pipeline, ordered by ID in descending order. The first job in the response will be the latest one. You can find more details in the Jobs API documentation.
Get the job artifacts: Finally, once you have the job ID, you can use the Job Artifacts API to fetch the artifacts for that job. Here’s an example API call:
This will return the artifacts for the given job. You can find more details in the Job Artifacts API documentation.
By chaining these API calls together, you can fetch the latest artifact file without knowing the pipeline ID. I hope this helps! Let me know if you have any other questions.
That looks great, let me try it here and see how I do. Much appreciated!
Thanks @gitlab-greg got the setup to work from. Just wondering in that last step if it’s possible to download a specific file amongst many or is it a download all as a zip option only?
@Calicoder, in the documentation that Greg shared there’s an endpoint to download a single artifact.