String to boolean conversion in workflow expressions #163013
-
|
Hi, In a workflow, a step wants to produce a boolean value in its outputs. Since the outputs are written in the text file Then, if we want to use that output value in boolean expressions, sometimes it works, sometimes it doesn't. For instance, in the same job, this works in a subsequent step: However, in a subsequent job, it doesn't: The input parameter We get the following error message when running the workflow: The following condition works: Why is the output value sometimes accepted as a boolean and sometimes not? Can we force some kind of conversion to boolean? Something like When we generate an input in a step using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Hi! Great question — you’ve pinpointed one of the subtle (and confusing) behaviors of GitHub Actions. All values written to $GITHUB_OUTPUT are treated as strings, even if you write true, false, 1, or 0. That’s why:
You're already doing the right thing by using:
This forces a proper boolean conversion, and is currently the best and most reliable way to pass a string-as-boolean to inputs typed as Can we force type in $GITHUB_OUTPUT?Unfortunately, no. There's no way to set a native boolean type in If you plan to use the output in multiple places as a boolean, consider defining a helper expression:
Or alternatively:
|
Beta Was this translation helpful? Give feedback.
Hi!
Great question — you’ve pinpointed one of the subtle (and confusing) behaviors of GitHub Actions.
All values written to $GITHUB_OUTPUT are treated as strings, even if you write true, false, 1, or 0.
That’s why:
In if: expressions, steps.check.outputs.rebuild works because it's being evaluated in a boolean context, where "true" (a non-empty string) is truthy.
But in a with: input (like passing build: ${{ needs.check_version.outputs.rebuild }} to a reusable workflow), the system expects a true boolean type, not a string. Hence the error.
You're already doing the right thing by using:
build: ${{ needs.check_version.outputs.rebuild == 'true' }}This forces a proper boolean conversio…