Running GitHub Super-Linter in Azure Pipelines

 
 
  • Gérald Barré

This post is part of the series 'Coding style'. Be sure to check out the rest of the blog posts of the series!

GitHub Super-Linter is a simple combination of various linters to help validate your source code. The end goal of this tool:

  • Prevent broken code from being uploaded to your repository
  • Help establish coding best practices across multiple languages
  • Build guidelines for code layout and format
  • Automate the process to help streamline code reviews

Instead of using many linters individually in your CI, you can use Super-Linter to rule them all. It can currently validate 30 different kinds of files including Azure Resource Manager (ARM), AWS CloudFormation templates, CSS, Dockerfile, EditorConfig, HTML, JavaScript, JSON, Markdown, OpenAPI, PowerShell, Protocol Buffers, Python3, Shell, Terraform, TypeScript, XML, YAML.

Super-Linter is easy to integrate in a GitHub workflow thanks to the provided action. But this doesn't mean you cannot use it in another build system such as Azure Pipelines. Indeed, Super-Linter is released as a Linux Docker image. So, if you can run a Docker image, it's ok. Hopefully, Azure Pipelines can run Docker images from a Linux runner.

Azure Pipelines allows to run containers using 2 ways:

  • Container jobs: Azure Pipelines pull the image and run the steps into it
  • Docker command line on a Linux machine

Container Jobs have constraints on the image that the Super-Linter doesn't meet. So, we need to use the later method.

YAML
trigger:
- '*'

# Use multiple jobs, so the linter can work in parallel to the build.
# This also allows to run the Linter on Linux whereas you build can run on Windows or Mac.
jobs:
  - job: lint
    pool:
      vmImage: 'ubuntu-20.04'
    steps:
    - script: docker pull github/super-linter:latest
      displayName: Pull GitHub Super-Linter image
    - script: >-
        docker run \
          -e RUN_LOCAL=true \
          -v $(System.DefaultWorkingDirectory):/tmp/lint \
          github/super-linter
      displayName: 'Run GitHub Super-Linter'

  - job: build
    pool:
      vmImage: 'windows-2019'
    steps:
    - script: dotnet build

You can configure the Super-Linter by adding environment variables (documentation). For instance, you can disable a specific linter by adding a variable to the docker run command:

YAML
    - script: >-
        docker run \
          -e RUN_LOCAL=true \
          -e VALIDATE_POWERSHELL=false \
          -v $(System.DefaultWorkingDirectory):/tmp/lint \
          github/super-linter

To configure the linters, you need to check the documentation of the individual linters: Supported Linter.

If everything's ok, the step should be green:

If there is a linter error, the pipeline fails and you should see the reported errors in the log:

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub