为什么要循环的外壳在github动作中不起作用

发布于 2025-02-10 18:21:31 字数 717 浏览 1 评论 0原文

我有一个应该多次运行基准的操作,但是在循环内首次执行命令后,包含循环的步骤结束。

我可以使用更简单的情况来重现问题 -

name: ci-pipeline
on: ["push"]
jobs:
  benchmark:
    steps:
      - name: run a loop
        run: |
          for run in {1..3}; do
            date;sleep 1;
          done

当我本地运行for for loop时(上面的所有管道)时,我会得到:

Fri Jun 24 13:25:57 CEST 2022
Fri Jun 24 13:25:58 CEST 2022
Fri Jun 24 13:25:59 CEST 2022

但是,在GitHub Action中,我得到:当使用时:

  for run in {1..3}; do
    date;sleep 1;
  done
  shell: sh -e {0}
  env:
    PIP_EXTRA_INDEX_URL: ***url1 ***url2

返回我得到的只有:

Fri Jun 24 10:15:40 UTC 2022

I have an action that is supposed to run a benchmark multiple times, however the step containing the loop ends after first execution of a command inside the loop.

I could reproduce the issue with a simpler case - with plain shell commands below

name: ci-pipeline
on: ["push"]
jobs:
  benchmark:
    steps:
      - name: run a loop
        run: |
          for run in {1..3}; do
            date;sleep 1;
          done

When I run the for loop locally (everything below pipe above), I get:

Fri Jun 24 13:25:57 CEST 2022
Fri Jun 24 13:25:58 CEST 2022
Fri Jun 24 13:25:59 CEST 2022

However, in GitHub Action, when using:

  for run in {1..3}; do
    date;sleep 1;
  done
  shell: sh -e {0}
  env:
    PIP_EXTRA_INDEX_URL: ***url1 ***url2

The return I get is only:

Fri Jun 24 10:15:40 UTC 2022

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彻夜缠绵 2025-02-17 18:21:31

它可能与您使用的shell字段有关。

您可以检查可与shell字段在官方文档上

我对GitHub Actions进行了测试,使用shell:bash

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - name: run a loop
        run: |
          for run in {1..3}; do
            date;sleep 1;
          done
        shell: bash

:按预期返回:

Fri Jun 24 12:17:42 UTC 2022
Fri Jun 24 12:17:43 UTC 2022
Fri Jun 24 12:17:44 UTC 2022

如果您想看看:

It may be related to the shell field you used.

You can check the available values you can use with the shell field on the official documentation

I made a test on a Github actions workflow using shell: bash:

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - name: run a loop
        run: |
          for run in {1..3}; do
            date;sleep 1;
          done
        shell: bash

And it returned as expected:

Fri Jun 24 12:17:42 UTC 2022
Fri Jun 24 12:17:43 UTC 2022
Fri Jun 24 12:17:44 UTC 2022

If you want to have a look:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文