6

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.
David Gardiner
17.3k20 gold badges86 silver badges126 bronze badges
asked Dec 14, 2020 at 10:24
2

1 Answer 1

5

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

answered Dec 14, 2020 at 10:43
Sign up to request clarification or add additional context in comments.

8 Comments

I don't see how the step is getting abbr seeing as you never created an environment variable called abbr. Also you are using the env context inside run which doesn't work
Are you sure what you are saying. I attached logs which proves different things than you are saying.
From what i recall ` run: echo "abbr=$(date '+tuesday%y%m%d')" >> $GITHUB_ENV` it created env variable.
Ahh ok that makes sense now I wasn't aware of the GITHUB_ENV variable
What can I say more than logs 🙂 both statements were printed, so it appears to be working
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.