GITHUB_ENV Variable in GitHub Actions

淺唱寂寞╮ 提交于 2021-01-24 08:15:27

问题


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/action-create-branch@v2.0.1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          branch: release/${{ steps.tuesday.outputs.abbr }}

Error:

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

回答1:


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

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/action-create-branch@v2.0.1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          branch: release/${{ env.abbr }}

Here a logs from running this:



来源:https://stackoverflow.com/questions/65287308/github-env-variable-in-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!