如何在Github Actions中丢掉工作? [英] How to fail a job in Github Actions?

查看:73
本文介绍了如何在Github Actions中丢掉工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Github动作工作流程.此工作流程可在Linux,Mac和Windows上运行.

I'm developing a Github actions workflow. This workflow runs on Linux, Mac and Windows.

作为工作流程的一部分,我必须检查2个环境变量是否相等.如果没有,请-失败.

As part of the workflow, I have to check whether 2 environment variables are equal. If they doesn't - fail the job.

As described here, Github Actions support if: condition:

steps:
- run: # How can if make a cross platform failure here?
  if: ${{ envA }} != ${{ envB }}

如果上述条件成立,如何使工作失败? 起初,我考虑过脚本,但是必须有一种更优雅的方式来使工作失败.

How can I make the job fail, if the above condition is true? At the beginning, I thought on a script, but there must be a more elegant way to fail a job.

推荐答案

我会做run: exit 1.这将在所有三个平台上以退出代码1退出.

I'd do run: exit 1. That will simply exit with an exit code of 1, on all three platforms.

证明它是跨平台的: https://github.com/rmunn/Testing/runs /220188838 ,它运行以下工作流程:

Proof that it's cross-platform: https://github.com/rmunn/Testing/runs/220188838 which runs the following workflow:

name: Test exiting on failure

on: [push]

jobs:
  build:

    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v1
    - name: Try to fail
      run: exit 1
    - name: Print message if we don't fail
      run: echo Should not get here

(此答案的较早版本建议使用"/bin/false",但这仅适用于Linux和OS X).

(An earlier version of this answer recommended "/bin/false", but that would only work on Linux and OS X).

这篇关于如何在Github Actions中丢掉工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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