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 ?
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
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct. :) The custom pipeline will run on whatever commit/branch it is triggered on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.