hammerkit
  • About
  • Installation
  • Getting started
  • Build file
    • Environment Variables
    • References
    • Includes
  • Task
    • Dependencies
    • Needs
    • Caching
    • Container
    • Watching
    • Extending
  • Service
    • Container
    • Kubernetes
  • Labels
  • CLI
    • Init
    • ls
    • Execute
    • Store / Restore
    • Clean
    • Validate
    • Help
  • External Links
    • Docker Hub
    • Homebrew Repository
  • Release Blog
    • Release 1.4.0
    • Release 1.5.0
  • Contribution
    • Roadmap
    • Publishing
Powered by GitBook
On this page
  • Shell environment
  • .env file
  • Defined values in the build file

Was this helpful?

  1. Build file

Environment Variables

Environment variables can be used from three different sources. Shell environment, .env files or predefined values inside the build file.

Shell environment

Environment variables which are available from the shell environment get passed into the command before execution.

.hammerkit.yaml
tasks:
  example:
    envs:
      VERSION: $VERSION
    cmds:
      - echo $VERSION

Each environment variable that is used, should be specified in the envs of the task. Hammerkit ensures that the environment variable is defined, otherwise will throw an error to prevent undesired behavior.

.env file

Environment variables can be defined in the .env file. Those are recommended for secret values that should not be committed nor public.

.env
NPM_TOKEN=abc
.hammerkit.yaml
tasks:
  example:
    envs:
      NPM_TOKEN: $NPM_TOKEN
    cmds:
      - npm publish

Defined values in the build file

Environment variables can be defined in the build file itself. They are can be defined for the entire build file or only for specific tasks.

.hammerkit.yaml
envs:
  NODE_VERSION: 14.16.0
  
tasks:
  example:
    cmds:
      - echo $NODE_VERSION
      
  override_example:
    envs:
      NODE_VERSION: 14.0.0
    cmds:
      - echo $NODE_VERSION
PreviousBuild fileNextReferences

Last updated 2 years ago

Was this helpful?

The scope of the defined environment variables are fixed to the build file they are defined in. Neither nor tasks will have access to those.

referenced
included