Search code examples
dockerenvironment-variablesbitbucketbazelbitbucket-pipelines

How can I configure bazel tests to run a docker container in a bitbucket pipeline?


I have a bitbucket pipeline that runs a set of tests via bazel, some of which need to invoke docker commands (integration tests).

When I run this pipeline, I get this error:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Things I've verified:

  • The tests pass locally (i.e. not running in the pipeline)
  • The DOCKER_HOST environment variable is being correctly set in the pipeline

My bitbucket-pipelines.yml file has the docker service specified for the step with bazel like so:

pipelines:
  default:
    - step:
        services:
          - docker
        script:
          - bazel test //...

I would expect this configuration to be sufficient for the tests to run correctly.


Solution

  • It turns out bazel does not pass environment variables through to tests by default.

    Here's the fix:

    bazel test --action_env=DOCKER_HOST //...

    https://bazel.build/docs/user-manual#action-env