# Using a return code in a if: condition

**URL:** <https://forum.gitea.com/t/using-a-return-code-in-a-if-condition/11741>\
**Category:** Actions\
**Created:** [October 10, 2025, 9:03pm UTC](https://forum.gitea.com/t/using-a-return-code-in-a-if-condition/11741 "2025-10-10T21:03:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cshabazian](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@cshabazian](https://forum.gitea.com/u/cshabazian)\
**Post date:** [October 10, 2025, 9:03pm UTC](https://forum.gitea.com/t/using-a-return-code-in-a-if-condition/11741/1 "2025-10-10T21:03:11Z")

</div>

I’m trying to setup an action (scan a container image with trivy) where it will exit the action prior to pushing the image if the trivy scan has a return code of non-zero.

Here is what I have:

> ```
> - name: Run Trivy Scan
> 
> run: trivy image --scanners vuln --severity CRITICAL my.image --exit-code 1 --ignorefile /etc/trivy/trivyignore.txt
> 
> id: trivy.status
> 
> - name: Exit if the scan fails
> 
> if: ${{ steps.trivy.status != 0 }} 
> 
> run: exit 1
> 
> ```

But the if never gets triggered and it just skips past this even though the scan has a return value of 1. I’m sure I just have my syntax wrong, but I can’t find anything that tells me how to use a return code in an if: condition.

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![mariusrugan](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mariusrugan](https://forum.gitea.com/u/mariusrugan)\
**Post date:** [October 23, 2025, 9:13pm UTC](https://forum.gitea.com/t/using-a-return-code-in-a-if-condition/11741/2 "2025-10-23T21:13:50Z")

</div>

Good artists copy, great artists … are inspired:

Why don’t you use their action ?

And yes if you want to do it very simple, see the permalink to their bash script  
(returnCode=$? etc.) and run both actions in a simple run block:

```sh
run: |
   trivy image --scanners vuln ...
   line 2

```

> <https://github.com/aquasecurity/trivy-action/blob/master/entrypoint.sh#L65>
