22

From here I learned that Bitbucket Pipeline supports ifs statements.

How do I do multi-line blocks inside if statements?

This doesn't compute:

    script:
      - if [ $BITBUCKET_BRANCH == "master" ];
        then;
          echo Line1
          echo line2
        fi;
ripper234
  • 222,824
  • 274
  • 634
  • 905

2 Answers2

51

Bitbucket pipelines are written in YAML, so you can take full advantage of the YAML language.

For multiline, you can also use either | or > operators.

- >
  if [ $BITBUCKET_BRANCH == 'master' ]; then
    echo "We are on master :)"
  else
    echo "We are not on master :("
  fi

More information: https://yaml-multiline.info/

NB: I guess this use-case was just an example, but you can also filter pipelines steps by branches directly: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html#Configurebitbucket-pipelines.yml-SectionDescription

Flo Schild
  • 5,104
  • 4
  • 40
  • 55
  • 8
    this should be the accepted answer, so much better as in the pipeline runs as single statement – DrCord Mar 17 '20 at 19:30
  • for some reason using > operator was throwing syntax errors for the if else statement but using | worked perfectly – Darren Mar 30 '23 at 11:19
15

I found that this works:

- if [ $BITBUCKET_BRANCH == 'master' ]; then
- echo "We are on master"
- fi
BlueM
  • 3,658
  • 21
  • 34