Member-only story
REST APIs — The Silver Bullet in Pipeline Automation
How REST APIs can automate tasks in your CI/CD pipelines

As we know, there is no silver bullet in IT. Crowning REST APIs as the silver bullet in pipeline automation is only meant to emphasize the great potential REST APIs can bring for the whole automation landscape in the CI/CD pipelines. How so? Let’s explore it through a few use cases.
Use Case 1: Automating SonarQube Project Creation in the CI Pipeline
Adding SonarQube scan in the GitHub Actions CI pipeline is easy, we can simply call the following action sonarsource/sonarqube-scan-action
:
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@427bad70165a74f9d7133d48ea31b482a53ee9fa
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
However, automation for SonarQube scan should not stop at this step. This step assumes your project has already been manually set up in SonarQube. Let’s push the automation yardstick a bit further — to include the project creation in SonarQube in your GitHub Actions CI workflow as well. This is where SonarQube REST APIs shine.
Let’s think a bit and gather the requirement. We want our CI workflow to achieve the following:
- Query SonarQube by triggering the SonarQube API call to see if our project already exists.
- If it already exists, scan by calling maven sonar plugin or the SonarScan action mentioned above.
- If the project doesn’t exist already, create the project in SonarQube first by triggering the SonarQube API call, then proceed to scan.
Let’s explore the SonarQube documentation on projects related to APIs. Here are the two APIs we are interested in:
Putting them into our GitHub Actions CI workflow, we now have the following: