Backstage sonarqube integration - "No project with key exist"
Opened this issue ยท 6 comments
๐ Description
I have been trying to integrate backstage with sonarqube . I have tried the instruction given on https://roadie.io/backstage/plugins/sonarqube/ and also tried https://github.com/backstage/community-plugins/blob/main/workspaces/sonarqube/plugins/sonarqube-backend/README.md . But nothing is working. I am getting "no project with key exists. In token/api I am sending token generated from administration tab. I have tried project token and user token (squ..., and sqp...). Can anyone please tell me exact config , suposing that my sonarqube instance is https://test.sonar.net/sonarqube.
To debug the issue, in Postman I hit API [https://test.sonar.net/sonarqube/api/components/search?qualifiers=TRK&componentKeys=test:projectKey"] . With project token it gives me correct result but with usertoken it gives me 401 unauthorized, (though I have created user token using admin account). Also, in Postman when I hit the same api via backstage host like https://<backstage_host>/api/sonarqube/components/search?qualifiers=TRK&componentKeys=test:projectKey , then it return html which is loging page of my backstage host.
๐ Expected behavior
๐ Actual Behavior with Screenshots
๐ Reproduction steps
Added config in app-config and added annotation with project key in the catalog-info
๐ Provide the context for the Bug.
No response
๐ฅ๏ธ Your Environment
No response
๐ Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
๐ข Have you read the Code of Conduct?
- I have read the Code of Conduct
Are you willing to submit PR?
None
then it return html which is loging page of my backstage host
Can I ask if other parts of the API are returning correct responses? Are you using a proxy or the sonarqube backend. If you are using the proxy, you may need to set the following setting to the internal url of the backend api.
sonarQube:
baseUrl: https://your.sonarqube.instance.com
can you also share the annotation you have set in the entity?
Please double check that the annotation is in one of the following format:
// Examples:
// instanceA/projectA -> projectInstance = "instanceA" & projectKey = "projectA"
// instanceA/tenantA:projectA -> projectInstance = "instanceA" & projectKey = "tenantA:projectA"
// instanceA/tenantA/projectA -> projectInstance = "instanceA" & projectKey = "tenantA/projectA"
The annotation I am using is:
sonarqube.org/project-key: "" as suggested in the document.
Can you please tell me with example what exactly should come in tenantA or projectA or what is instanceA in instanceA/projectA -> projectInstance = "instanceA" & projectKey = "projectA".
I have defined instanceA in app-config as given below but it not work for me:
sonarqube:
instances:
- name: default
baseUrl:
apiKey: squ_......
Can I ask if other parts of the API are returning correct responses? : Can you please explain what are you referring to "other parts of API" . If you are asking for other integrations are working, then yes jfrog artifactory plugin and jira plugin are working fine. Facing issue with sonarqube only.
Also, as I mentioned earlier in postman if I hit sonarqube api "api/components/search" , it works fine with project token, but if I hit same api with backstage host, it return backstage login page html
Are you using a proxy or the sonarqube backend. I tried with both but none of them worked.
you may need to set the following setting to the internal url of the backend api. What do you mean by that. I did add this in app-config. Is this the same you are talking about else please guide me.
The annotation I am using is: sonarqube.org/project-key: "" as suggested in the document.
Can you please tell me with example what exactly should come in tenantA or projectA or what is instanceA in instanceA/projectA -> projectInstance = "instanceA" & projectKey = "projectA". I have defined instanceA in app-config as given below but it not work for me:
sonarqube: instances: - name: default baseUrl: apiKey: squ_......
I have no idea, I'm not familiar with the plugin. But looking at the documentation it suggests the following:
https://github.com/backstage/community-plugins/tree/main/workspaces/sonarqube/plugins/sonarqube-backend#example---single-global-instance
so the value of sonarqube.org/project-key
is supposed to be defined by two parts (instance name, project key) separated by /
I've found a way to make it works.
In fact, there is a key/value missing in app-config.yaml
which is instanceKey
.
From the code we can see in router.test.ts
it('query default instance when instanceKey not provided', async () => {
getBaseUrlMock.mockReturnValue({ baseUrl: DUMMY_INSTANCE_URL });
const response = await request(app).get('/instanceUrl').send();
expect(getBaseUrlMock).toHaveBeenCalledTimes(1);
expect(getBaseUrlMock).toHaveBeenCalledWith({
instanceName: undefined,
});
expect(response.status).toEqual(200);
expect(response.body).toEqual({ instanceUrl: DUMMY_INSTANCE_URL });
});
That helped me to see there is a fallback on default instance which is localhost if not provided, which is of course not the case because I use sonarcloud.io.
By updating my config like bellow it works :
sonarqube:
name: myName
instanceKey: myInstance
baseUrl: https://sonarcloud.io
apiKey: *************************
I've made a PR to update README here : #2026