【问题标题】:Saving GITHUB_ENV Variable in GitHub Actions在 GitHub Actions 中保存 GITHUB_ENV 变量
【发布时间】:2021-07-02 09:02:53
【问题描述】:

我正在尝试使用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 }}

错误:

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

【问题讨论】:

标签: github-actions


【解决方案1】:

我稍微更改了您的创建分支步骤,但如果您解决了日期格式问题,您的 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 }}

这是运行此日志的日志:

【讨论】:

  • 我不明白这一步是如何得到abbr 的,因为您从未创建名为abbr 的环境变量。此外,您正在使用 run 内的 env 上下文 doesn't 工作
  • 你确定你在说什么。我附上了证明与您所说的不同的日志。
  • 据我回忆`运行:echo "abbr=$(date '+tuesday%y%m%d')" >> $GITHUB_ENV` 它创建了环境变量。
  • 啊,好吧,现在我不知道 GITHUB_ENV 变量是有道理的
  • 除了日志我还能说什么?两个语句都被打印了,所以它似乎正在工作
猜你喜欢
  • 1970-01-01
  • 2020-06-14
  • 2021-07-12
  • 2021-09-19
  • 2020-02-16
  • 1970-01-01
  • 2022-11-20
  • 2020-04-20
  • 2019-06-26
相关资源
最近更新 更多