Friday, April 19, 2024
HomePowershellAutomating SonarCloud with PowerShell – Half 2 Onboarding a Challenge – Jonathan...

Automating SonarCloud with PowerShell – Half 2 Onboarding a Challenge – Jonathan Medd’s Weblog


Warning: this publish incorporates unsupported API calls, so use at your personal threat

One of many most important causes I began trying on the SonarCloud api was to have the ability to automate the onboarding of latest GitLab tasks into SonarCloud. We didn’t wish to have to try this manually through the UI, quite through a pipeline job. In half 1 of this sequence I demonstrated the fundamentals of the API and the PSSonarCloud PowerShell module, partially 2 we’ll have a look at easy methods to onboard a challenge into SonarCloud.

False Begin

Initially this regarded like it might be a really simple job, the SonarCloud Net Api has documentation for making a project:

In order a part of the PSSonarCloud module I added a operate “`New-SonarCloudProject . You might use it as the next to create a challenge, all you want is a SonarCloud API key with permission to create a challenge, then the SonarCloud organisation, GitLab challenge title and challenge id:

The challenge will seem in SonarCloud and all appears to be like good:

Nonetheless, a problem will come up once you try to run some evaluation in opposition to the challenge, it can fail and complain that the SonarCloud challenge isn’t built-in together with your repo.

I found through a neighborhood discussion board publish and an commentary within the UI that the API name above doesn’t embody the mixing with the code repo – evaluate that challenge with a challenge which was onboarded through the UI and it shows integration with GitLab:

A New Hope

The discussion board publish prompt an unsupported choice could be to look at the API name by means of browser improvement instruments and use that:

So off to Google Chrome improvement instruments we go……

By trying on the API name used when including a challenge through the UI, we are able to see {that a} URL of /api/alm_integration/provision_projects is used

The payload contained two gadgets:

  • installationKeys – the GitLab challenge id
  • group – the SonarCloud group

Consequently the New-SonarCloudProjectALMIntegrated operate was born. So we are able to now absolutely onboard a challenge with the next:

The resultant challenge has been absolutely onboarded:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments