Feature request: Nicer way to pass all ENV variables to script
Having to define one by one all github secrets on env and then pass them one by one to envs is cumbersome. Ideally adding a flag for passing all github secrets down to the script.
@AnderUstarroz OK. Got it.
Thanks @appleboy other than this is the best SSH package for Github actions I have found. But with easier/cleaner ENV management would be perfect.
For instance I have a project using about 20 Env variables and Docker picks the right ones just by filtering the needed ones with the flag --env-list:
obs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
export_all_envs: true
script: |
docker run --env-list ./env.list MY_IMAGE:latest
Where export_all_envs or all_envs Exports al github envs and secrets down to the script so they can be used like regular environment variables:
echo $MY_ENV
Currently doing something like this implies a lot of manual work defining every single variable one by one.
The quickest way to test if the feature works would be just by printing the env vars with printenv. It should display all github secrets: ${{ secrets.* }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
all_envs: true
script: |
printenv
all_env: Injects all Github secrets as environment variables within the script.
I would say this is the major issue of the package at the moment, and the only reason we didn't use it in production (Too much manual work when having certain number of variables). But if this feature is applied would be awesome!
Maybe I can export all ENVS with GITHUB_ and INPUT_ as prefixes as below:

so developer can use all variables in the script.
@AnderUstarroz I can't add repository secret as global env dynamically so the best way is to define secret as environment manually.
@appleboy I see.. but still would be super useful if we can have the rest of the variables automatically exported. Regarding Github secrets we can define them manually just once within the global space of a Github action, that way they will be available for all jobs:
env:
SOME_VARIABLE: ${{ secrets.my_var1 }}
ANOTHER_VARIABLE: ${{ secrets.my_var2 }} <-- Here all secrets defined manually within the Task global space.
jobs:
some_job:
name: some_job
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
all_envs: true
script: |
printenv <----- Should display SOME_VARIABLE, ANOTHER_VARIABLE and ideally also GITHUB_* and INPUT_*
another_job:
name: another_job
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
all_envs: true
script: |
printenv <----- envs also available here
@appleboy agree with @AnderUstarroz on this one, if we have to define the github secrets manually only once at the root of the file that won't really be a problem. But at the moment we have to define over and over which variables are passed down to the script on every job which is a lot of boilerplate and hard to maintain.
@peterschwarzdev @AnderUstarroz OK. I understand your requirement. I will add a new parameter all_envs to pass all environments to the host.
This would be great!
Looking forward to having this!
Was this implemented?
I will take it.
@peterschwarzdev @nekiro
- name: pass all ENV variables to the script
uses: appleboy/[email protected]
env:
INPUT_FOO: "BAR"
INPUT_AAA: "BBB"
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
allenvs: true
script: |
echo "I am $INPUT_FOO, thanks"
echo "I am $INPUT_AAA, thanks"
echo "$GITHUB_BASE_REF"
echo "$GITHUB_REF"
Add allenvs flag to pass all environments to the scripts, only support the prefix value as INPUT_ and GITHUB_
Add
allenvsflag to pass all environments to the scripts, only support the prefix value asINPUT_andGITHUB_
@appleboy Is there a reason why you only allow to pass environments starting with INPUT_ and GITHUB_ ?
@abhinayagarwal
Because the GitHub Action Container by default will pass in variables that start with INPUT_ and GITHUB_.
Let's say I have the following step where I already have N number of env variables, none of which start with either INPUT_ or GITHUB_:
- name: pass all ENV variables to the script
uses: appleboy/[email protected]
env:
FOO_1: "BAR_1"
FOO_2: "BAR_2"
...
FOO_N: "BAR_N"
with:
envs: FOO_1, FOO_2, ..., FOO_N
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
As you can see I have to pass all of these env manually using envs. Adding allenvs: true support for these environment variables and automatically supplying them to the script would be nice, without having to append them with INPUT_ or GITHUB_.