Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is pipelines smart enough to read the same file name in different branches and choose the right one?

Deleted user July 30, 2018

Example: I want to have for different branches a Dockerfile. When I specify the branch to trigger my pipeline and run " $ docker build . " , does bitbucket pipelines understand which dockerfile should take based on the branch or do I have to declare something else in my bitbucket-pipelines file ?


1 answer

1 accepted

0 votes
Answer accepted
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 30, 2018

Hi Aris,

Bitbucket Pipelines checks out the relevant branch for your branch pipeline configuration.

For example:

pipelines:
branches:
master:
- step:
script:
- cat Dockerfile # Will print the Dockerfile on master branch.
staging:
- step:
script:
- cat Dockerfile # Will print the Dockerfile on staging branch.

Try it out for yourself if you want!

As an aside, if you want to have different Dockerfiles for multiple branches, it might be better (depending on your workflow) to have multiple Dockerfiles across all branches, so that your branches don't get out of sync.

pipelines:
branches:
master:
- step:
script:
- docker build -f Dockerfile . # Will build a docker image off the Dockerfile on master branch.
staging:
- step:
script:
- docker build -f Staging-Dockerfile . # Will build a docker image off the Staging-Dockerfile on staging branch.

Then you don't need to worry about someone accidentally overwriting the Dockerfiles on different branches.

Thanks,

Phil

Deleted user July 31, 2018

Thanks Philip, 

That's awesome, one more thing in the same topic, when you build a custom pipeline and you build it against a specific branch in BitBucketUI - same behaviour would be applied, checking out the relevant branch ?

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2018

Correct. :) The custom pipeline will run on whatever commit/branch it is triggered on.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events