Hello SonarQube Community, @Bachri_Abdel
I’m using the SonarQube API to add a group to multiple projects and assign multiple permissions to that group. However, when I run my script, it only applies the first permission (issueadmin
) and ignores the rest.
What I’m Trying to Do:
- Assign a group to multiple projects.
- Grant the group all six permissions:
issueadmin
,securityhotspotadmin
,scan
,admin
,user
,codeviewer
- Use the
/api/permissions/add_group
endpoint to assign each permission.
I know only one Permission per api call.
I cant try the Permission Template becuase when i add the template it will overide the exsisitng permission and erase that and add the template i passed so , i cant go with template.
Issue I’m Facing:
- The API only applies the first permission (
issueadmin
) and does not add the rest. - This happens even when I loop through each permission separately.
- There’s no error returned from the API—it just doesn’t apply the additional permissions.
import requests
import time
SONARQUBE_URL = "https://test.com"
AUTH_TOKEN = "testkey"
PROJECT_KEYS = ["test_proj_key"]
GROUP_NAMES = ["test group"]
PERMISSIONS = ["issueadmin", "securityhotspotadmin", "scan", "admin","user", "codeviewer", ]
API_URL = f"{SONARQUBE_URL}/api/permissions/add_group"
auth = (AUTH_TOKEN, "")
for project in PROJECT_KEYS:
for group in GROUP_NAMES:
for permission in PERMISSIONS:
params = {
"projectKey": project,
"groupName": group,
"permission": permission
}
response = requests.post(API_URL, auth=auth, params=params)
if response.status_code == 204:
print(f'Successfully added permission "{permission}" for group "{group}" to project "{project}".')
else:
print(f'Failed to add permission "{permission}" for group "{group}" to project "{project}". Status: {response.status_code}, Response: {response.text}')