为什么要循环的外壳在github动作中不起作用
我有一个应该多次运行基准的操作,但是在循环内首次执行命令后,包含循环的步骤结束。
我可以使用更简单的情况来重现问题 -
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能与您使用的
shell
字段有关。您可以检查可与
shell
字段在官方文档上我对GitHub Actions进行了测试,使用
shell:bash
:按预期返回:
如果您想看看:
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 documentationI made a test on a Github actions workflow using
shell: bash
:And it returned as expected:
If you want to have a look: