Skip to content
Advertisement

How can I extract contents from a file stored in gitlab repos

Using the gitlab-python package, I’d like to extract lines from all Dockerfiles. Using my code below, I am able to get project names and url to the repo I want but how can I ensure there is a Dockerfile and read the contents of the Dockerfile.

JavaScript

The output I get now is :

JavaScript

Advertisement

Answer

You can use the project.files.get() method (see documentation) to get the Dockerfile of the project.

You can then print the content of the Dockerfile/do whatever you want to do with it like this:

JavaScript

You might have to adjust the branch name in case there are multiple branches.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement