Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can bitbucket-pipeline.yml refer another yml file

Kiran April 10, 2020

I am in need to configure bitbucket-pipeline for each of the branches.  While we can have branch based configuration, the file becomes too big and often results in conflicts due to frequent updates.

Is it possible for the bitbucket-pipeline.yml refer to other yml file. What i am looking for is the parent yml file indicate for branch1 refer this branch1.yml, and branch2 refer branch2.yml.?

Or any way to split into multiple yml files?

 

3 answers

2 accepted

2 votes
Answer accepted
Ronald C_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 10, 2020

Hi Kiran,

I'm afraid that it's not possible to have multiple yml configurations within the repository.
A workaround you can do is by having a bash script with all your commands within it for a specific branch then use the yml configuration to run the bash script.

For example:

  1. Create bash script: Bash Scripting Tutorial - linuxconfig.org
    #!/bin/bash 

    echo "Commands for a specific branch"
    curl bitbucket.org
  2. Save the bash script within the repository
  3. Modify the yml configuration to run the bash script according to the branch
    pipelines:
      default:
        - step:
            script:
              - ./default-commands.sh 
      branches:
        master:
          - step:
              script:
                - ./master-commands.sh
        feature/*:
          - step:
              script:
                - ./feature-commands.sh 

     

You may also make use of Pipelines' default variables - $BITBUCKET_BRANCH
Variables in pipelines - Atlassian Documentation

pipelines:
  default:
    - step:
        script:
          - ./$BITBUCKET_BRANCH.sh 

 You may need to make sure the script's name is exactly the same as the branch name.

 

Hope this helps. :)

Regards,
Ronald

0 votes
Answer accepted
Ahmad Jawabra
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 8, 2022

Hi everyone, when I'm trying to run the pipeline I got:
bash: ./shared-pipeline.sh: Permission denied.

Maciej Sterma
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 30, 2022

Did you run 

chmod +x shared-pipeline.sh

Stefan Herklotz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 7, 2022

it's also possible to run it as follows:

script:
  - bash  ./shared-pipeline.sh
Like Irina Litinskaja likes this
2 votes
Irina Litinskaja
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2023

Is there an alternative way, for example:

.....
script:
    - include: 'steps/build.yml'
    - include: 'steps/deploymentXX.yml'

    - include: 'steps/sendEmail.yml'

 

 

Best, Irina

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events