'How to use Bazel in Azure Pipelines?

I tried to set up an Azure Build Pipeline that uses Bazel (0.26.0)

My pipeline YAML definition file looks like this:

trigger:
- master

pool:
  vmImage: 'windows-2019'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    bazel version
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

Currently, I try only to find out which Bazel version is installed by calling bazel version - but Azure DevOps reports:

'bazel' is not recognized as an internal or external command,
operable program or batch file.
Cmd.exe exited with code '9009'.

I wonder how I can install and run Bazel in a Azure pipeline - any hints on this?

It seems that this project got it working. But I do not understand how.



Solution 1:[1]

You got this error because you use Microsoft-hosted agent, in those agents bazel is not installed. In the example you provided they use Self Hosted (Private) Agent and they install bazel in their agent machine.

1) Install Self Hosted Agent in your private machine and install bazel in the machine.

2) Install bazel during the build pipeline with choco (simple script task):

choco install bazel

After you install it you can use it.

P.S I tried to install via choco and I got an error but bazel indeed installed and in the next step bazel version gave results, so in the installation task put continueOnError = true. (the error is in the python step, if your project not with python it's ok).

Solution 2:[2]

This is how I install Bazel and Azure Pipeline on a windows-2019 image:

steps:
  - script: |
      echo 'Install Bazel via Choco'
      choco install bazel
    displayName: 'Install dependencies'

  - script: |
      bazel version
    displayName: 'Show bazel version'

Solution 3:[3]

In the meantime, Bazel and Bazelisk come already preinstalled. Seems Bazel takes over the world.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vertexwahn
Solution 2 Vertexwahn
Solution 3 Vertexwahn