Home > Blockchain >  Using set-output as a workflow command fails with exit code 3
Using set-output as a workflow command fails with exit code 3

Time:10-29

I do not know whether here is a problem in one of my steps regarding an github-workflow-job.

The step looks like this:

- name: check_tf_code
   id: tf_check 
   run: |
     terraform fmt -check
     echo '::set-output name=bash_return_Value::$?'

and the error output for this step in the log is: Error: Process completed with exit code 3

What could be the problem here? Is GitHub not able to make a bash evaluation for $? to get the info whether the last (terraform) command was successful or not?

CodePudding user response:

Run steps are run with set -eo pipefail (see docs); this means that if any command has a non-zero exit status, the job aborts, including when the command is part of a pipeline.

In your case, this means that if terraform fmt -check has a non-zero exit status, the next line is never run.

Then, your output would be literally $? because Bash doesn't expand anything in single quotes. You'd have to use

echo "::set-output name=bash_return_Value::$?"

but you already know that when this line is hit, the value of $? is 0.

If you want to do something in case a command fails, you could do

if ! terraform fmt -check; then
    # Do something
fi

because if conditions don't trigger the set -e behaviour.

CodePudding user response:

Oh okay, thanks for the quick help.

Then I do not need the output statement as the run steps already has a set -e behaviour.

  • Related