0

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..

Mario
  • 11
  • 1
  • I've used [this action](https://github.com/marketplace/actions/read-properties) for something similar. It's not exactly setting the GITHUB_ENV, but creating an output for each property informed. That may be a useful workaround for now. – GuiFalourd Dec 20 '22 at 12:27
  • @GuiFalourd it needs docker right?? – Mario Dec 20 '22 at 12:29
  • This action needs an ubuntu runner (with Docker installed), as it uses a Dockerfile to run the implementation. The proper Github runner for ubuntu (free) will do the trick. – GuiFalourd Dec 20 '22 at 12:30
  • @GuiFalourd Thank you but I am looking for something with no docker dependency, and I am using self-hosted runners – Mario Dec 20 '22 at 12:33
  • No problem. I recommend to add this point to the question :) – GuiFalourd Dec 20 '22 at 12:34

1 Answers1

0

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

Fcmam5
  • 4,888
  • 1
  • 16
  • 33