Is there any way that I can add all the properties to the $GITHUB_ENV

694 views Asked by At

Currently I have a properties file(test.properties) it has all the key pair values, Is there any way that i can add these values to $GITHUB_ENV ??

test.properties ->

  • username1=user1
  • username2=user2

I haven't added anything in the workflow yet just want to echo all the properties from the proeperties file..

1

There are 1 answers

0
Fcmam5 On

A naïve approach would be iterating over the content of your .properties file line-by-line and setting them as environment variables:

steps:
  - uses: actions/checkout@v3
  - shell: bash
    run: |
      while IFS= read -r line || [[ -n "$line" ]]
      do
        echo "$line" >> $GITHUB_ENV
      done < test.properties
  - run: echo ${{ env.username1 }}
  - run: echo ${{ env.username2 }}

The bash line that reads the file line-by-line is taken from this answer.

Please note that this example will only work if you have a .properties file with no comments and contains only key=value pairs