在 GitHub Actions 中保存 GITHUB_ENV 变量

car*_*iem 5 github-actions

我正在尝试使用date一步保存变量名称。但是,在后面的步骤中,它似乎是未定义的(或空的?)。我在这里缺少什么?

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 }}
Run Code Online (Sandbox Code Playgroud)

错误:

refs/heads/release/ is not a valid ref name.
Run Code Online (Sandbox Code Playgroud)

Krz*_*tof 5

我稍微改变了您的创建分支步骤,但如果您解决日期格式问题,您的 slo 应该可以工作。 在此输入图像描述

我改变了它并且它有效。

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 }}
Run Code Online (Sandbox Code Playgroud)

这是运行此命令的日志:

在此输入图像描述

  • 除了打印两条语句之外,我还能说什么,所以它似乎正在工作 (2认同)