Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables from file in Actions #6178

Open
jesvilnie opened this issue Apr 5, 2024 · 2 comments
Open

Environment variables from file in Actions #6178

jesvilnie opened this issue Apr 5, 2024 · 2 comments

Comments

@jesvilnie
Copy link

Having the possibility to define environment variables in the Actions is crucial in most situations, but it would be really nice to have the possibility to specify these variables from a file, so they can be reused across multiple actions without the need of replicate the list of env vars in each action.

It would be something like this:

---
name: "my_script"
runner_type: "remote-shell-cmd"
description: "Remote CMD with envs form file"
enabled: true
env_file: "/path/to/my/env/file"

Or as a parameter:

---
name: "my_script"
runner_type: "remote-shell-cmd"
description: "Remote CMD with envs form file"
enabled: true
parameters:
    env_file: 
       type: "string"
       default: "/path/to/my/env/file"
@chain312
Copy link
Contributor

chain312 commented Apr 7, 2024

I think we can write an application package, put the environment variable configuration in the package configuration, and then use this configuration for all the actions in this package.

@nzlosh
Copy link
Contributor

nzlosh commented May 2, 2024

A workaround to get this functionality would be to provide a json file with the environment variables that is read in an action prior to calling core.remote and then pass the contents via the env parameter.

For example (not tested)

/path/to/action_env.json

{
  "username": "user1",
  "url": "https://example.com/",
  "project_id": "abcd2134"
}

Load the environment file. StackStorm will automatically deserialise JSON content from stdout. The deserialised JSON can be published for use in subsequent actions.

  load_env:
    action: core.local
    input:
      - cmd: cat /path/to/action_env.json
    next:
      - do: run_remote_cmd
        when: <% succeeded() %>
        publish:
          env_kw: <%  result().stdout %>

  run_remote_cmd:
    action: core.remote
    input:
        hosts: somehost.example.com
        env: <% ctx().env_kw %>
        cmd: "echo $USERNAME $URL $PROJECT_ID"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants