2

I am using Gitlab v4 api to list a project's variables, while the code returns vars for some projects, it also returns 403 forbidden response for some other projects. And the error is not very verbose so I'm confused what could be the possible reason. I'm using a group access token which has read api permissions on all projects within the group. Below is the piece of code:

group = gl.groups.get(20, lazy=True)
group_projects = group.projects.list(include_subgroups=True, all=True)
for group_project in group_projects:
    project = gl.projects.get(group_project.id)
    project.variables.list(get_all=True)

error: b'{"message":"403 Forbidden"}'

What might be the reason for this?

blackPanther
  • 181
  • 1
  • 3
  • 14

1 Answers1

1

GitLab's API response isn't really clear, but projects that are archived, have an empty repository, or have the repository/CI feature disabled, will not have variables available. You can guard against this by checking for those features in your loop:

if (
    project.archived
    or project.empty_repo
    or project.repository_access_level == "disabled"
    ):
    continue

Or something to that effect. You can also check in the UI if the variable settings are actually visible.

nejc
  • 181
  • 3