Create Timestamp with GitHub Actions View article history Edit article

Published: , Updated:
Talks about: <a class="post-tag post-tag-github" href="/tags/github">github</a>, <a class="post-tag post-tag-github-actions" href="/tags/github-actions">github actions</a>, and <a class="post-tag post-tag-timestamp" href="/tags/timestamp">timestamp</a>

In case you are into calver or have another reason to create a timestamp with GitHub Actions, do the following:

name: <PIPELINE>
jobs:
  build:
    runs-on: <RUN_ON>
    steps:
      - name: Create release version
        id: <ID>
        run: echo "::set-output name=<NAME>::$(date +'%Y.%m.%d-%H%M%S')"

The special syntax ::set-output name=<NAME>:: declares that the output of the command (echo) should be saved in a variable called <NAME>. Together with the <ID> of the pipeline step, this value can be referenced with the expression ${{ steps.<ID>.outputs.<NAME> }} in the following steps of your pipeline.