Skip to content

allow adding env variables via CLI #11338

Closed
@matifali

Description

@matifali

Context

Coder now has a resource named coder_env that can be used to inject environment variables into the workspace.

There is one use case where a module author would like to do this conditionally depending on if another binary is in the PATH. This could be used to install and configure vscode extensions for the code-server if it is already installed and inject the environment variables for automatic login.
One example is the JFrog VS Code extension that supports auto-login if we set the following environment variables.

JFROG_IDE_URL="https://jfrog.example.com"
JFROG_IDE_ACCESS_TOKEN="XXXXXXXXXXXXXXXXXXXXXXX"

Suggestion

Provide a CLI command coder env that can be used to set/unset environment variables within a coder_script.

This can then be used to set the environment variables conditionally.

if command -v code-server > /dev/null 2>&1; then
  code-server --install-extension jfrog.jfrog-vs code-extension
  coder env set JFROG_IDE_URL --body "https://jfrog.example.com"
  coder env set JFROG_IDE_ACCESS_TOKEN --body "XXXXXXXXXXXXXXXXXXXXXXX"
else
  echo "🤔 code-server is not installed, skipping JFrog extension installation."
fi

The syntax is based on the same pattern as gh variable set.

cc: @bpmct @mafredri @kylecarbs

Tip

As a bonus, this can also allow modifying $PATH, e.g.,
coder env set PATH --body "/tmp/code-server/bin/coder-server:$PATH"

Metadata

Metadata

Assignees

Labels

cliArea: CLI

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions