How to fail a job in Github Actions?

流过昼夜 提交于 2020-06-12 08:06:16

问题


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

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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/57903836/how-to-fail-a-job-in-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!