Connect Bazel to Artifactory

JFrog Artifactory Documentation

Products
JFrog Artifactory
Content Type
User Guide

To use Artifactory as the registry for your Bazel client, you need to complete these two tasks:

Prerequisite: Before connecting the Bazel client to Artifactory, you must have an existing Bazel Modules repository in Artifactory. For more information, see Create a Bazel Modules Repository.

Authenticate Bazel to Artifactory

Before using your Bazel client with Artifactory, you need to add Artifactory authentication information to your netrc file. The credentials are required for Bazel to authenticate to your Artifactory repository.

To authenticate Bazel to Artifactory:

  1. Open the netrc file in a text editor. The file location varies by OS, for example:

    • Linux and Unix (macOS): ~/.netrc

    • Windows: %USERPROFILE%\_netrc

  2. In the netrc file, add the following snippet:

    machine [JFrogPlatformURL]
    login <USERNAME>
    password <AUTH>

    Where:

    • [JFrogPlatformURL]: Your orgainzation's Artifactory URL

    • <USERNAME>: Your Artifactory username

    • <AUTH>: Your Artifactory identity token

    For example:

    machine company.jfrog.io
    login jeffry
    password k9M4f6V8b2c1n7H3g5T0j2x4R1z9Q5w7E3d8F6c4N2m1K8v0B3s5A
  3. Save the changes to your file.

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

Add Artifactory Registry to Bazel

After adding Artifactory credentials to your netrc file, you need to configure your Bazel client with the repository information.

To add the Artifactory registry to Bazel:

  1. Open or create the .bazelrc file. If the file already exists, its location varies by operating system. For example:

    • Linux and Unix (macOS): ~/etc/bazel.bazelrc

    • Windows: %ProgramData%\bazel.bazelrc

  2. In the .bazelrc file, add the following snippet:

    <COMMAND> --registry=https://[JFrogPlatformURL]/artifactory/api/bazelmodules/<REPO_NAME>

    Where:

    • <COMMAND>: The command you want to configure to work with the Artifactory repository. Options include:

      • common: Set all commands to resolve from Artifactory

      • build: Set build commands to resolve from Artifactory

      • fetch: Set fetch commands to resolve from Artifactory

      • test: Set test commands to resolve from Artifactory

    • [JFrogPlatformURL]: Your organization's Artifactory URL

    • <REPO_NAME>: The name of your Bazel Modules repository in Artifactory

    For example:

    common --registry=https://company.jfrog.io/artifactory/api/bazelmodules/bazel-remote
  3. Save the changes to the file.

Note

You can also use JFrog Set me up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.

Next steps: