Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace "Process completed with exit code 1." with a custom error Annotation?

I have echo "::error title=Foo::Bar" in one of my actions so that I can give a more descriptive error annotation than just "Process completed with exit code 1.", and this has the desired effect of adding an error annotation to the job and workflow with the given title and text. However, the "Process completed with exit code 1." is still also there, so I get two errors from every such job. If I exit with code 0 then the job status changes from red-x-mark to green-check-mark which is not what I want.

Is there a way to only replace the single error with my custom error, without changing the status of the job or having other side effects?

Example workflow code:

name: test
on:
  push:
    branches: [ "main" ]
jobs:
  foo:
    runs-on: ubuntu-latest
    steps:
      # TODO suppress default "Process completed with exit code 1." error
      - name: Error
        run: |
          echo "::error title=Foo::Bar"
          (exit 1)
like image 738
Sparr Avatar asked May 20 '26 17:05

Sparr


1 Answers

https://github.com/actions/github-script exposes the ability to execute javascript against the Github api, including core.setFailed

   - steps:
     - name: Foo
        uses: actions/github-script@v3
        with:
          script: |
            core.setFailed('Custom error message')

This will result in the Foo step failing, with the corresponding red (X) icon and impact on later steps, without an extraneous exit code annotation.

like image 173
Sparr Avatar answered May 22 '26 19:05

Sparr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!