Integrate SonarCloud with AWS CodeCommit and CodeBuild

Header Image
Header Image
SonarCloud, AWS CodeCommit and AWS CodeBuild logos

What is SonarCloud?

In this article, I’m going to guide you on how to integrate SonarCloud with your AWS Codebuild environment.

What you need?

  • SonarCloud Account

Step #1 — Creating a SonarCloud Project — Creating the project

In the next page, click on Create a Project Manually — Selecting manual option

In the next page, enter a project key and display name you like and click Set up. — Setting up the project

It will setup the project. Then click Manually to configure the project manually — Selecting Manual Option

Then Sonarcloud will ask about your build and Operating system. I have selected Other for build and Linux as the OS because CodeBuild projects run on Linux. — Selecting Build Option and OS

After selecting those two options, you will get the SONAR_TOKEN and a command that you can use in an upcoming step. Save the token and a command in a place where you can easily access.

Step #2 — Creating a CodeCommit Project

CodeBuild — Dashbaord

Then Click Create Repository > Give the repository a name and Create the repository.

CodeBuild — Creating New Repository

After creating the repository, Clone the repository . After that, you can add your code into the repository.

Here, we need to add a special file to initiate the build process in CodeBuild. It is known as the buildspec.yml file. Create a file called buildspec.yml and paste the below content in it.

CodeBuild — Sample Buildspec

Then change the following values with the values you got when creating the sonarcloud project

  • SONARCLOUD_ORG = Your Sonar Cloud Organization name
  • PROJECT_KEY = Your Sonar Project Key
  • SONARCLOUD_TOKEN = Your Sonar Project Token

Then push the entire codebase to the repository.

Step #3 — Creating CodeBuild Project

CodeBuild — Create CodeBuild Project

When creating the project, select the CodeCommit repository you created earlier. Then click create to create the project.

CodeBuild — Start Build

After creating the project, You can run the build. If everything is correctly configured, the sonar scanner will analyze the project. After everything is completed, you will be able to see the analyses report on Sonarcloud. — Project Analyses

Keep reading about SonarCloud and AWS

In love with tech ever since I know what a computer is :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store