Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a multi-line if block on Bitbucket Pipeline?

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;
like image 663
ripper234 Avatar asked Aug 14 '18 12:08

ripper234


2 Answers

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

like image 74
Flo Schild Avatar answered Sep 22 '22 21:09

Flo Schild


I found that this works:

- if [ $BITBUCKET_BRANCH == 'master' ]; then
- echo "We are on master"
- fi
like image 33
BlueM Avatar answered Sep 19 '22 21:09

BlueM