Github操作:检查步骤状态 [英] Github Actions: check steps status

查看:147
本文介绍了Github操作:检查步骤状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CI工作有一些步骤可能会引发错误.我不想在每个步骤都出现错误的情况下重新启动工作流,并且想要转到检查这些步骤并以失败方式完成此工作的最后一步. 但是我无法获取先前步骤的状态信息.

I have in my job for CI some steps which can throw an error. I don't want restart workflow on every step with error and want to go to the last step that checks those steps and complete this job as fail. But I can't get status info previously steps.

name: CI
on: [pull_request]
jobs:
  myjob:
    runs-on: ubuntu-latest
    steps:
      - name: Step 1
        id: hello
        run: <any> 
        continue-on-error: true
      - name: Step 2
        id: world
        run: <any> 
        continue-on-error: true
      - name: Check on failures
        if: job.steps.hello.status == failure() || job.steps.world.status == failure()
        run: exit 1

当我在"if"或"run"中使用下一个构造时,将得到:steps-> {},job.steps-> null.

When I use next constructions in "if" or "run" then will get: steps -> {}, job.steps -> null.

如何获取状态信息?

推荐答案

查看有关步骤上下文的文档,它看起来不包含除outputs以外的有关该步骤的任何信息.这些必须由步骤明确定义.这就是为什么步骤上下文为空{}.

Looking at the documentation for the steps context, it doesn't look like it contains any information about the step other than outputs. These must be explicitly defined by steps. That is why the steps context is empty {}.

https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#steps-context

不幸的是,据我所知,没有可访问步骤的默认状态.该解决方案涉及从每个步骤手动定义状态输出变量.

Unfortunately, as far as I can tell, there is no default status for a step that can be accessed. The solution involves manually defining a status output variable from each step.

name: CI
on: [pull_request]
jobs:
  myjob:
    runs-on: ubuntu-latest
    steps:
      - name: Step 1
        id: hello
        run: echo ::set-output name=status::failure
        continue-on-error: true
      - name: Step 2
        id: world
        run: echo ::set-output name=status::success
        continue-on-error: true
      - name: Dump steps context
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
        run: echo "$STEPS_CONTEXT"
      - name: Check on failures
        if: steps.hello.outputs.status == 'failure' || steps.world.outputs.status == 'failure'
        run: exit 1

这将创建以下上下文输出,并且作业失败.

This creates the following context output and the job fails.

{
  "hello": {
    "outputs": {
      "status": "failure"
    }
  },
  "world": {
     "outputs": {
      "status": "success"
    }
  }
}

https://help.github.com/zh_CN/articles/metadata-syntax-for-github-actions#outputs https://help.github.com/en/articles/development-tools-for-github-actions#set-an-output-parameter-set-output

这篇关于Github操作:检查步骤状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆