• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • All
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • 3D printing
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Chatbots
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DataOps
    • Developers life
    • DevOps
    • Digital Days
    • Digital Twin
    • Docker
    • eHealth
    • Enterprise Architecture
    • Event Sourcing
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • All
    • Bloggers
    • Speakers
Home » Flutter & SonarQube with Azure Pipelines
  • Flutter & SonarQube with Azure Pipelines

    • By Tom de Wildt
    • Quality Assistance & Test 2 years ago
    • Quality Assistance & Test 0 comments
    • Quality Assistance & Test Quality Assistance & Test
    Flutter & SonarQube with Azure Pipelines

    Quality assurance is one of the most important things when it comes to building applications. Tools like SonarQube can help developers write cleaner and more maintainable code. It is best to include the quality assurance step in a CI/CD pipeline, to make sure the quality is high before deploying any code. In this blog post I will show you how to use SonarQube in conjunction with Flutter and Azure Pipelines.

    SonarQube

    For anyone who did not know already, SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities. SonarQube offers reports on duplicated code, coding standards, unit tests, code coverage, code complexity, comments, bugs, and security vulnerabilities.

    Pipeline

    You must first install the Azure Pipelines Flutter, Azure Pipelines SonarQube and the Sonar Flutter extensions before you can start building your pipeline. It is also a good idea to setup a service connection for SonarQube in Azure Pipelines, you can read more about that here.

    Step 1: Define triggers

    The following code snippet makes sure that the pipeline only triggers on pushes to the master branch.

    trigger:
      branches:
        include:
          - master
    pr: none

    Step 2: Define variables

    It’s a best practice use a variables section to make it easy for other developers to update the pipeline in the future. I defined two variables one for the Flutter channel and one for the Flutter version.

    variables:
      FlutterChannel: 'stable'
      FlutterVersion: 'latest'

    Step 3: Setup environment

    You must first install Flutter, setup SonarQube and setup some environment variables before you can test and analyze the app. It’s recommended to use the macOS-latest image for the pipeline.

    The macOS-latest image already has Java 7, 8, 11, 12, 13 and 14 installed. You can select the version you want by appending JAVA_HOME_<VERSION>_X64 to the $PATH variable and setting the $JAVA_HOME variable to JAVA_HOME_<VERSION>_X64. You also need to append the FlutterToolPath variable (exposed by the extension) to the $PATH variable to allow the other steps in the pipeline to use the flutter command line tools.

    Note: The Sonar Flutter plugin only supports Java 11 or later.

    jobs:
      - job: Test
        pool:
          vmImage: 'macOS-latest'
        steps:
          - task: FlutterInstall@0
            displayName: Setup flutter
            inputs:
              channel: '$(FlutterChannel)'
              version: '$(FlutterVersion)'
    
          - task: SonarQubePrepare@4
            displayName: Setup sonar
            inputs:
              SonarQube: 'SonarQube Service Connection'
              scannerMode: 'CLI'
              configMode: 'file'
    
          - task: PowerShell@2
            displayName: Setup environment
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "##vso[task.prependpath]$(JAVA_HOME_11_X64)"
                Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$(JAVA_HOME_11_X64)"
                Write-Host "##vso[task.prependpath]$(FlutterToolPath)"
                Write-Host "##vso[task.prependpath]$(FlutterToolPath)/cache/dart-sdk/bin"

    Make sure your sonar-project.properties contains the following values.

    sonar.projectKey=<SONAR_PROJECT_KEY>
    sonar.projectName=<SONAR_PROJECT_NAME>
    sonar.projectVersion=1.0
    
    sonar.sources=lib
    sonar.tests=test
    
    sonar.sourceEncoding=UTF-8

    Step 4: Test & analyze

    All the dependencies must be installed by using flutter pub get before you can test and analyze the app. The Sonar Flutter plugin needs two files to correctly display the coverage. The first file is a file containing the tests. The second file is an lcov report containing the coverage. You can generate these files by running flutter test --machine > tests.output and flutter test --coverage.

          - task: CmdLine@2
            displayName: Run install
            inputs:
              script: 'flutter pub get'
    
          - task: CmdLine@2
            displayName: Run test
            inputs:
              script: 'flutter test --machine > tests.output'
    
          - task: CmdLine@2
            displayName: Run coverage
            inputs:
              script: 'flutter test --coverage'
    
          - task: SonarQubeAnalyze@4
            displayName: Run analyze
    
          - task: SonarQubePublish@4
            displayName: Run publish
            inputs:
              pollingTimeoutSec: '300'

    Step 5: Complete pipeline

    The complete pipeline should look somewhat like this:

    trigger:
      branches:
        include:
          - master
    pr: none
    
    variables:
      FlutterChannel: 'stable'
      FlutterVersion: 'latest'
    
    jobs:
      - job: Test
        pool:
          vmImage: 'macOS-latest'
        steps:
          - task: FlutterInstall@0
            displayName: Setup flutter
            inputs:
              channel: '$(FlutterChannel)'
              version: '$(FlutterVersion)'
    
          - task: SonarQubePrepare@4
            displayName: Setup sonar
            inputs:
              SonarQube: 'SonarQube Service Connection'
              scannerMode: 'CLI'
              configMode: 'file'
    
          - task: PowerShell@2
            displayName: Setup environment
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "##vso[task.prependpath]$(JAVA_HOME_11_X64)"
                Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$(JAVA_HOME_11_X64)"
                Write-Host "##vso[task.prependpath]$(FlutterToolPath)"
                Write-Host "##vso[task.prependpath]$(FlutterToolPath)/cache/dart-sdk/bin"
      
          - task: CmdLine@2
            displayName: Run install
            inputs:
              script: 'flutter pub get'
    
          - task: CmdLine@2
            displayName: Run test
            inputs:
              script: 'flutter test --machine > tests.output'
    
          - task: CmdLine@2
            displayName: Run coverage
            inputs:
              script: 'flutter test --coverage'
    
          - task: SonarQubeAnalyze@4
            displayName: Run analyze
    
          - task: SonarQubePublish@4
            displayName: Run publish
            inputs:
              pollingTimeoutSec: '300'

    Conclusion

    By using Azure Pipelines and SonarQube you can easily implement a quality assurance process for your Flutter project. I hope this post helps you implement your own pipeline. Feel free to leave a comment below if you have any questions.

    azure pipelines sonarqube

    Share this

Tom de Wildt

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Verantwoordelijkheid pakken in jouw eigen persoonlijke …

    Verantwoordelijkheid pakken in jouw eigen persoonlijke … Stephan Versteegh - 2 years ago

  • TestBash Netherlands 2018

    TestBash Netherlands 2018 Rouke Broersma - 4 years ago

Data Discovery Channel

  • Explainable AI - Break open the blackbox

  • Toekomstvaste microservice data architecturen

  • Modern Data Platform

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel Always active
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Manage options Manage services Manage vendors Read more about these purposes
Voorkeuren
{title} {title} {title}