How to get the current time as an environment variable in actions?

I hope to automatically create a new release through Actions and set the name to the current time, but I have failed many times. How can I do this?

Just like this
image

Assuming your build is running on Linux, you can just use the date command in a step, e.g:

- name: set release date
  run: |
    echo "RELEASE_DATE=$(date --rfc-3339=date)" >> ${GITHUB_ENV}

That’ll give you the current date in YYYY-MM-DD format, adjust the date command line if you need another format.

3 Likes


It’s failed.
Maybe my configuration is wrong?

image

It looks like you’re sending the date into ${TIME} instead of $GITHUB_ENV. To set an environment variable you need to send it to $GITHUB_ENV in the following format:

echo "{name}={value}" >> $GITHUB_ENV

4 Likes

image
It still have some problem.

You’ll likely need to wrap it in an expression syntax, otherwise it’ll just output as a string:

${{ env.TIME }}

2 Likes

All right.It’s now working.
Thank you so much! :grinning:
@airtower-luna @thomasshaped

2 Likes