carpiediem
carpiediem

Reputation: 2028

Saving GITHUB_ENV Variable in GitHub Actions

I'm trying to save a variable name in one step, using date. But, in a later step, it seems to be undefined (or empty?). What am I missing here?

jobs:
  # Create release branch for the week
  branch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Format the date of next Tuesday
        id: tuesday
        run: echo "abbr=$(date -v+tuesday +'%y%m%d')" >> $GITHUB_ENV

      - name: Create a branch with next tuesday's date
        uses: peterjgrainger/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          branch: release/${{ steps.tuesday.outputs.abbr }}

Error:

refs/heads/release/ is not a valid ref name.

Upvotes: 6

Views: 8999

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40553

I slightly changed your create branch step but your slo should work if you solve issue with date formatting. enter image description here

I changed it and it works.

jobs:
  # Create release branch for the week
  branch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Format the date of next Tuesday
        id: tuesday
        run: echo "abbr=$(date '+tuesday%y%m%d')" >> $GITHUB_ENV

      - name: Read exported variable
        run: |
          echo "$abbr"
          echo "${{ env.abbr }}"

      - name: Create a branch with next tuesday's date
        uses: peterjgrainger/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          branch: release/${{ env.abbr }}

Here a logs from running this:

enter image description here

Upvotes: 5

Related Questions