I have the following simple job:
name: Issue comment handler
on: [issue_comment, workflow_dispatch]
jobs:
issue_commented:
if: github.event.comment.body == 'test'
name: Issue comment
runs-on: ubuntu-latest
steps:
- name: echo-out
run: echo '${{ toJSON(github.event) }}'
When using that if
conditional with this expression, it invariably skips the job. I haven't found anywhere in the docs that say why it skips, but I'm guessing it is because the body is untrusted user input and may contain malicious code if executed directly?
As suggested, I add an env variable instead:
name: Issue comment handler
on: [issue_comment, workflow_dispatch]
jobs:
issue_commented:
if: ${{ env.COMMENT == 'test' }}
name: Issue comment
runs-on: ubuntu-latest
steps:
- name: echo-out
run: echo '${{ toJSON(github.event) }}'
env:
COMMENT: ${{ github.event.comment.body }} # Added env variable here
When I try to use:
if: env.COMMENT == 'test'
I get: Unrecognized named-value: 'env'. Located at position 1 within expression: env.COMMENT == 'test'
When I try:
if: ${{ env.COMMENT == 'test' }}
I get: Unrecognized named-value: 'env'. Located at position 1 within expression: env.COMMENT == 'test'
When I try to use:
if: ${{ $COMMENT == 'test' }}
I get: Unexpected symbol: '$COMMENT'. Located at position 1 within expression: $COMMENT == 'test'
What am I doing wrong? Also, is it just me or are the docs quite bad and have lots of holes?