DEV Community

George Shuklin
George Shuklin

Posted on

Elegant way to assert if env variable is defined for a single recipe in Just

I found the way, which I think, is the most elegant, to check if environment variable is defined.

foo:
  @test {{ env("FOO") }}
Enter fullscreen mode Exit fullscreen mode

If FOO is not defined, it will fail:

error: Call to function `env` failed: environment variable `FOO` not present
  ——▶ Justfile:2:12
  │
2 │   @test {{ env("FOO") }}
  │            ^^^             
Enter fullscreen mode Exit fullscreen mode

Maybe there is a build-in way, but I wasn't able to find it. I want it to be checked for a single recipe, not for the whole file.

Top comments (0)