Problem with YAML syntax

Hello everyone!

I am writing my workflow file on YAML but it says there is an error on line 4

              if [ "${{ github.ref }}" = "refs/heads/develop" ]; then
                  echo "::set-env name=COMPOSE_SUFFIX::staging"
                  echo "::set-env name=PROJECT::clerk_test"
              elif [ "${{ github.ref }}" = "refs/heads/master" ]; then
                  echo "::set-env name=COMPOSE_SUFFIX::prod"
                  echo "::set-env name=PROJECT::clerk"
              else
                  echo "Please select develop (staging) or master (prod) branch"
                  exit 1
              fi

Can anybody tell me what is wrong with my syntax?

Hey @lpzhang5, can you share the full YAML file? Either inline or a link to your repository. It would make it easier for us to assist you. The reason I want some more context is that the code you have shared is not YAML, it’s a Bash script. The problem you are facing might be related to how you are embedding the Bash script in the YAML file, but without more context, I can only guess.

Hello @thomasjo ,

The full YAML file is here

there is some bash script embedded for setting env vars, it says there is problem at the line for ‘elif’

Thanks for that. The problem is caused by missing indentation in the multiline block for the Bash script. Add indentation to the entire Bash script block and your problem should be resolved.

name: Deploy Application
on: [workflow_dispatch]
jobs:
    deploy:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - name: Set variables
              run: |
                if [ "${{ github.ref }}" = "refs/heads/develop" ]; then
                    echo "::set-env name=COMPOSE_SUFFIX::staging"
                    echo "::set-env name=PROJECT::clerk_test"
                elif [ "${{ github.ref }}" = "refs/heads/master" ]; then
                    echo "::set-env name=COMPOSE_SUFFIX::prod"
                    echo "::set-env name=PROJECT::clerk"
                else
                    echo "Please run with master (prod) or develop (staging) branch"
                    exit 1
                fi
1 Like

Thank you!

It is fixed now. Quite a few headaches due to this minor but subtle problem!

1 Like