GitHub Actions – Jenkins管道中“fixed”状态的等价物?

huangapple go评论59阅读模式
英文:

Github Actions - Equivalent of Jenkins pipeline "fixed" status?

问题

在Jenkins工作中,通常有“通过”、“失败”和一些其他常见的运行后工作状态。还有一种固定状态,我认为是指如果作业在之前失败后通过了。对于Actions是否有类似的情况呢?我在文档中没有找到相关信息。我想要的是,只有在失败后有通过的情况才将我的作业发布到Slack,而不是每次成功都发布。

英文:

So in a Jenkins job, it has the usual post-run job status of "pass", "fail" and some others. There's also a fixed status; Which I think is if a job passes after it has failed before. Is there anything like this for Actions? I couldn't see anything in the docs, I'd like to have my job post to slack only if something has passed after a failure, but not every success

答案1

得分: 1

以下是您提供的内容的中文翻译:

Jenkins post 条件 fixed 适用于当前运行成功且前一个运行失败或不稳定的情况。

GitHub Actions 没有类似的 post 条件(详见此链接)。可以使用普通的操作,因此必须为此活动定义一个作业/步骤 - 以实现功能上的等效性。

您可以使用 needs 来定义它依赖的前一个作业,您可以使用 if 来定义构建状态条件。

上下文可用性(描述 if 条件中可用的数据)中,您可以看到 success 是可用的。

然而,对于上一个构建状态,查看 jobs.<job_id>.ifjobs.<job_id>.steps.if,没有适用属性的特殊功能或上下文存在。因此,必须通过请求查询上一个工作流程的结果状态。

您可以使用自己定义的作业和步骤执行此操作,或者利用市场上的操作,如 Get status of last workflow

它们的示例包括与您的条件情况匹配的步骤:

        if: ${{ success() && steps.last_status.outputs.last_status == 'failure' }}

在上下文中:

      - name: Build fixed slack message
        uses: rtCamp/action-slack-notify@v2.1.3
        if: ${{ success() && steps.last_status.outputs.last_status == 'failure' }}
        env: 
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_MESSAGE: 'Style check fixed now!'
英文:

The Jenkins post condition fixed applies if the current run is successful and the previous run failed or was unstable.

GitHub Actions does not have a post equivalent. A normal action can be used, so you have to define an job/step for this activity - for a functional equivalent.

You use needs to define the previous jobs it depends on. You use if to define the build state conditions.

From the context availability, which describes what data is available in the if condition, you can see that success is available.

However, for the last build status, looking at both jobs.<job_id>.if and jobs.<job_id>.steps.if, no special function nor context with applicable property exists. So the previous workflow result status has to be queried for via request.

You can do this with your own defined jobs and steps, or make use of a Marketplace action like Get status of last workflow.

Their example includes a step that matches your condition case too:

        if: ${{ success() && steps.last_status.outputs.last_status == 'failure' }}

in context:

      - name: Build fixed slack message
        uses: rtCamp/action-slack-notify@v2.1.3
        if: ${{ success() && steps.last_status.outputs.last_status == 'failure' }}
        env: 
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_MESSAGE: 'Style check fixed now!'

huangapple
  • 本文由 发表于 2023年4月19日 17:29:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定