Unable to use env variable in Github Actions if statement

I am trying to run a simple workflow like this.

name: Create Release

on:
  push:
    branches:
      - master

jobs:
  job1:
      - name: Set Environment
        run: |
          string="Hello World"
          echo "string=$string" >> $GITHUB_ENV

  job2:
    needs: job1
    if: contains(env.string, 'Hello')
    runs-on: ubuntu-latest
    steps:
      - name: Set up Repository
        uses: actions/checkout@v2

However, I get an error

The workflow is not valid. .github/workflows/create-release.yml Unrecognized named-value: 'env'

I am not able to access the env variable string in the if statement. How can solve this issue?

Environment variables aren’t persistent across jobs, you’ll need to use job outputs for that: