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

setting up pipeline when to use default vs branches?

Deepesh Belani March 17, 2024

Hi All, I am new to BB pipeline. I wanted to create a pipeline for running lint for python followed by deploying to GCP CF. Have few questions on designing the pipeline as below.

BB branches: dev, test, release. Default branch is dev.

1] I want to understand when to use pipeline with default vs branches? 

2] I want to run lint only when code is checked in dev branch. I want to run PyTest only when code is merged in test How do I design this in pipeline?

Here is a pipeline code I have created so far. Request your feedback. TIA!

image: python:3.11

pipelines:
# default:
# - step:
# caches:
# - pip
# name: "Check flake8"
# script: # Modify the commands below to build your repository.
# - pip install flake8
# - flake8 --max-line-length=180 --ignore=E203,W503


branches:
dev:
- step:
name: "Deploy to dev GCP project"
image: google/cloud-sdk:latest
# deployment: test
script:
- pip install flake8
- flake8 --max-line-length=180 --ignore=E203,W503
- echo $DEV_API_KEYFILE > ~/.gcloud-api-key.json
- gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json
- gcloud functions deploy dev_bitbucket_linting --entry-point auth --runtime=python311 --timeout=240 --min-instances=1 --max-instances=10 --trigger-http --service-account=$DEV_SERVICE_ACCOUNT --region $DEV_GCP_REGION --project $DEV_GCP_PROJECT

test:
- step:
name: "Deploy to test GCP project"
script:
- pip install pytest
- pytest --junitxml=test-reports/report.xml
- echo $TEST_API_KEYFILE > ~/.gcloud-api-key.json
- gcloud auth activate-service-account --key-file ~/.gcloud-api-key.json
- gcloud functions deploy dev_bitbucket_linting --entry-point auth --runtime=python311 --timeout=240 --min-instances=1 --max-instances=10 --trigger-http --service-account=$TEST_SERVICE_ACCOUNT --region $TEST_GCP_REGION --project $TEST_GCP_PROJECT

 

 

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 19, 2024

Hi Deepesh,

1] I want to understand when to use pipeline with default vs branches?

The default pipeline runs on every push (excluding tag pushes) to the repository unless a branch-specific pipeline is defined. This can be used in the following cases:

  • You want the exact same pipeline to run when pushing to any branch of the repo.

  • You have branches pipelines for some branches, e.g. dev and test in your case, but you want a different pipeline to run for all the other branches.

This is our documentation for reference:

2] I want to run lint only when code is checked in dev branch. I want to run PyTest only when code is merged in test How do I design this in pipeline?

Since you want pipelines to run only for dev and test branches, you don't need to use the default pipeline.

The pipelines you have for dev and test branch will run every time there are new commits on dev or test respectively. Please keep in mind that the pipeline doesn't differentiate between a push of commits or a merge to a branch, so it will run in both cases.

You can adjust the commands of each pipeline's script depending on what you want to run for each branch.

You can also specify a different Docker image as a build container for each step with the keyword image, like you are doing for the step in dev pipeline.

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Deepesh Belani March 20, 2024

Thank you Theo for your answers this helps!

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 20, 2024

That's good to hear Deepesh and you are very welcome! Please feel free to reach out if you ever need anything else!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events