Download gitlab ci jobs artifacts using Python

Hi All,

I’m using the Gitlab Python API to get information from my projects pipelines and jobs. I want to download all the artifacts for the last pipeline of a projects, but I’m getting some issues with the method “job.artifacts”. It returns me an type error “TypeError: ‘list’ object is not callable”

This is what I’m doing:

image

Does anyone have an idea of why the method " job.artifacts(streamed=True, action=f.write)" is not working?

Thanks a lot in advance!
Veronica

1 Like

Yeah…I’m a bit late to the party, but perhaps this will help someone. My first job saves the artifacts, so I wrote the following to download and unzip.

if last_pipeline:
     pipeline_job = last_pipeline.jobs.list()[0]
     job = self.project.jobs.get(pipeline_job.id, lazy=True)
     file_name = '__artifacts.zip'
     with open(file_name, "wb") as f:
         job.artifacts(streamed=True, action=f.write)
     zip = zipfile.ZipFile(file_name)
     zip.extractall()
3 Likes

This one definitely helped me! Encountered the exact same error and this answer resolved it. Someone should update the python-gitlab API doc with this answer concerning fetching of artifacts from a job.