Search code examples
azureazure-devopsazure-pipelinesbazel

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

  • 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).