azure devops setup quality pipeline - devonfw/hangar GitHub Wiki

Setting up a Quality pipeline on Azure DevOps

In this section we will create a quality pipeline for analyzing project code with SonarQube. This pipeline will be configured in order to be triggered every time the test pipeline is executed successfully on a commit, and consumes the artifact produced by the build pipeline.

The creation of this pipeline will follow the project workflow, so a new branch named feature/quality-pipeline will be created and the YAML file for the pipeline will be pushed to it.

Then, a Pull Request (PR) will be created in order to merge the new branch into the appropriate branch (provided in -b flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using -w flag.

The script located at /scripts/pipelines/azure-devops/pipeline_generator.sh will automatically create this new branch, create a quality pipeline based on a YAML template appropriate for the project programming language or framework, create the Pull Request, and if it is possible, merge this new branch into the specified branch.

Prerequisites

  • This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with git pull).

  • Generate a SonarQube token (just follow the section "Generating a token").

Creating the pipeline using provided script

Usage

pipeline_generator.sh \
  -c <config file path> \
  -n <{pipeline_type} name> \
  -l <language or framework> \
  --sonar-url <sonarqube url> \
  --sonar-token <sonarqube token> \
  -d <project local path> \
  --build-pipeline-name <build {pipeline_type} name> \
  --test-pipeline-name <test {pipeline_type} name> \
  [-b <branch>] \
  [-w]
Note
The config file for the quality pipeline is located at /scripts/pipelines/azure-devops/templates/quality/quality-pipeline.cfg.

Flags

-c, --config-file            [Required] Configuration file containing {pipeline_type} definition.
-n, --pipeline-name          [Required] Name that will be set to the {pipeline_type}.
-l, --language               [Required] Language or framework of the project.
    --sonar-url              [Required] SonarQube URL.
    --sonar-token            [Required] SonarQube token.
-d, --local-directory        [Required] Local directory of your project.
    --build-pipeline-name    [Required] Build {pipeline_type} name.
    --test-pipeline-name     [Required] Test {pipeline_type} name.
-b, --target-branch                     Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided.
-w                                      Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag.

Examples

Quarkus project

./pipeline_generator.sh -c ./templates/quality/quality-pipeline.cfg -n quarkus-project-quality -l quarkus --sonar-url http://1.2.3.4:9000 --sonar-token 6ce6663b63fc02881c6ea4c7cBa6563b8247a04e -d C:/Users/$USERNAME/Desktop/quarkus-project {extra_args_quarkus} -b develop {openBrowserFlag}

Node.js project

./pipeline_generator.sh -c ./templates/quality/quality-pipeline.cfg -n node-project-quality -l node --sonar-url http://1.2.3.4:9000 --sonar-token 6ce6663b63fc02881c6ea4c7cBa6563b8247a04e -d C:/Users/$USERNAME/Desktop/node-project {extra_args_quarkus} -b develop {openBrowserFlag}

Angular project

./pipeline_generator.sh -c ./templates/quality/quality-pipeline.cfg -n angular-project-quality -l angular --sonar-url http://1.2.3.4:9000 --sonar-token 6ce6663b63fc02881c6ea4c7cBa6563b8247a04e -d C:/Users/$USERNAME/Desktop/angular-project {extra_args_angular} -b develop {openBrowserFlag}
⚠️ **GitHub.com Fallback** ⚠️