Conditional Job using Environment Variable

My request is simple … I want to run a job within jobs if it meets a condition of my choosing. I’ve seen posts using GitHub environment variables; but, I want to use my own env var.

Is this even possible?

Background: Trying to implement CI-CD on my website. I may change the HTML or CSS or JS on any release. If I change the HTML, I need to update my AWS s3 website configuration (indexdocument). Otherwise, I just need to copy the files to the s3.

I have this:

name: CI and CD

branches: [ master ]
branches: [ master ]
NEW_HTML: false
NEW_CSS: false
NEW_JS: false

runs-on: ubuntu-latest
needs: [copy-files-to-s3]
theChangedFiles: {{steps.get_file_changes.outputs.files }} steps: - name: Get file changes id: get_file_changes uses: trilom/file-changes-action@v1.2.3 with: output: ‘ ‘ - name: Echo file changes run: | echo Changed Files: {{steps.get_file_changes.outputs.files }}
- name: Check for new HTML
if: contains(steps.get_file_changes.outputs.files, ‘.html’)
run: $NEW_HTML = true

if: contains(${{ env.CHANGED_FILES }}, ‘.html’)

No matter how I structure this statement I get an error:

well it says
“Invalid workflow file”
The workflow is not valid. .github/workflows/main.yml (Line: 72, Col: 9): Unrecognized named-value: ‘env’. Located …


About the env context, you can only use it in the following scenarios:

  • the value of the with key;
  • the value of the step’s name key;
  • the value of the step’s env key;
  • in a step’s if conditional;
  • in the command lines of a run step.

In addition, you also used the incorrect expression syntax for if conditional in the workflow.
About the correct expression syntax, you can reference to the topic below: