Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there if-else block in bitbucket pipleline?

I am using bitbucket pipelines to deploy my code. I have multiple environments. I want to do different jobs depending on the environment (dev, test, pre-prod, prod). I want to know if there is if-else conditional ways to help me reduce duplicate code and reduce code.

like image 238
Zheng Fei Avatar asked Nov 20 '25 23:11

Zheng Fei


2 Answers

If your pipeline includes only default, it will execute in all envs.

You can include keywords in your pipeline to deal with that. In execution order, will be something like:

image: node:9.8.0
pipelines:
  branches: 
        #here, i'm saying to execute the step below only on branchs
    develop:
        #Here, when branch 'develop' 
     - step:
          script:
    master:
        #Here, when branch 'master' 
     - step:
          name: Buid Prod
          script:
          [....]

You can define other keywords to tell bitbucket when execute the steps, see more here, at docs

like image 162
Giovan Cruz Avatar answered Nov 22 '25 12:11

Giovan Cruz


it can be done by the below sample

- if []; then
-   #task
- elif []; then
-   #task
- else
-   #task
- fi
like image 26
Zheng Fei Avatar answered Nov 22 '25 14:11

Zheng Fei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!