Replace deprecated "set-env"

Dear Community,

I am using deprecated “set-env” and now I have to fix it.

I am using it like this:

            - name: Setup
              run: |
                  echo "::set-env name=version_prefix::# ${release_version}"
                  echo "::set-env name=file_content::${changelog_content}"
                  release_version: ${{ }}
                  changelog_content: ${{ }}

            - name: Update Log
              if: startsWith(env.file_content, env.version_prefix) != true
              run: echo -en "# $release_version\n$changes\n$(cat $changelog_filepath)" >$changelog_filepath
                  changelog_filepath: ${{ github.workspace }}/changelog/
                  release_version: ${{ }}
                  changes: ${{ steps.release_drafter.outputs.body }}

What is the new alternative for that?

Thank you!

This has been replaced by passing variables into $GITHUB_ENV.

For example:

echo "version_prefix=${release_version}" >> $GITHUB_ENV

The only thing I believe you’ll need to change in your workflow is echo commands and convert them to the new syntax. Be aware that this may be slightly different if your strings are multiline.

Edit: Thank you! It works. I was using the delimiter the wrong way. Now its fine. Thank you!

I tried this, but the action fails:

 Error: Unable to process file command 'env' successfully.
Error: Invalid environment variable format '## Bugs'

The strings are multiline.

@benwick91 can you share? I’m having trouble with this. My old env:

          PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"

If tried the new way like so:

      - name: Environment Variables
        run: |
          echo -e "PLAN=terraform\n${{ steps.plan.outputs.stdout }}" >> ${GITHUB_ENV}

I am using it this way:

                  echo "version_prefix=# ${release_version}" >> $GITHUB_ENV
                  echo "file_content<<{delimiter}
                  {delimiter}" >> $GITHUB_ENV

Your way seems to be right and the you sould can use it with ${PLAN}.

But in your old env you doesn’t use set-env. Can’t you use it the old way any more?

I hope this helps :slight_smile:

@benwick91 - yeah I guess the old way is still fine. I was under the assumption that it was the same as set-env and being deprecated. :man_facepalming: