Skip to content

Bazel rule used to import environment variables from a .env file.

License

Notifications You must be signed in to change notification settings

worldpeaceio/rules_envfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bazel env file rules

Build Status

This rule can be used to import environment vars into a Bazel workflow directly from an environment file.

Basic usage

In .env:

# Vars need to be quoted
SOME_ENV="Hello, world!"

In WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    # Get copy pase instructions for the http_archive attributes from the
    # release notes at https://github.com/worldpeaceio/rules_envfile/releases
)

load("@io_worldpeace_rules_envfile//:def.bzl", "envfile")
envfile(
    name = "envfile",
    files = [
        "//.env"
    ]
)

Example using an env var in a BUILD.bazel file:

load("@envfile//:environment.bzl", "SOME_ENV")

sh_test(
    name = "test",
    srcs = ["test.sh"],
    env = {
        "SOME_ENV": SOME_ENV,
    },
)