简体   繁体   English

运行未找到任何内容的 grep 命令时,github 工作流失败

[英]github worflow fails when running a grep command that does not found anything

I'm working on a workflow that has the following step:我正在研究具有以下步骤的工作流程:

  - name: Analyze blabla
    run: grep -Ri --include \*.ts 'stringToBeSearched' ./tmp/bla > ./tmp/results.txt
    shell: bash

This works well in the case the grep command founds something.这在 grep 命令找到某些东西的情况下效果很好。 Then the found lines are dumped into results.txt and the returncode is 1, and the workflow goes to the next step as expected然后将找到的行转储到results.txt中,returncode为1,工作流按预期进入下一步

But in the case the grep command does not found the searched strings, then an empty file is saved as result.txt (what correct until this point), but the result code is 0, and the step is set as failed, and the whole workflow fails.但是在grep命令没有找到搜索到的字符串的情况下,则将一个空文件保存为result.txt(到目前为止正确),但结果代码为0,并且步骤设置为失败,并且整个工作流失败。

Is there a way to not set the step as failed when the result code is 0?当结果代码为 0 时,有没有办法不将步骤设置为失败?

Thanks谢谢

You could use the continue-on-error step option:您可以使用continue-on-error步骤选项:

jobs.<job_id>.steps[*].continue-on-error jobs.<job_id>.steps[*].continue-on-error

Prevents a job from failing when a step fails.当步骤失败时,防止作业失败。 Set to true to allow a job to pass when this step fails设置为 true 以在此步骤失败时允许作业通过

Like:喜欢:

  - name: Analyze blabla
    continue-on-error: true
    id: grep
    run: grep -Ri --include \*.ts 'stringToBeSearched' ./tmp/bla > ./tmp/results.txt
    shell: bash

You.你。 could check the outcome of the step in order to understand if was failed or not like:可以检查步骤的outcome ,以了解是否失败,例如:

steps.<id>.outcome != 'success'

See outcome doc here在此处查看结果文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM