13

An Introduction to bitbucket pipeline

 3 years ago
source link: https://blog.knoldus.com/an-introduction-to-bitbucket-pipeline/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

An Introduction to bitbucket pipeline

Knoldus Blog Audio
Reading Time: 4 minutes

IIPWuSKZXj0vQst92gC9OW4fVOvApiMvlpN2YL4UDXYZ-ZFK574Vv1ZwBoA80aMFfB8Zy0IvlLPUFps74tdRmsg3Nm0okKtafgTfbjc_X2nUXB-5vLgamq3scV76xvUh9K_ULd9T

Bitbucket Pipelines is an integrated CI/CD service built into Bitbucket Cloud that’s integrated into the UI and sits alongside your repositories. It allows you to automatically build, test, and even deploy your code based on a configuration file in your repository.

CI/CD tools are an integral part of a software team’s development cycle. Whether you’re using it to automate tests, a release process, or deployments to customers, all teams can benefit by incorporating CI/CD into their workflow.

Some of the features of pipelines are:

Easy setup

It is very easy to get started with the Bitbucket pipelines. It’s a 2-step process to configure a pipeline and there is a number of templates of language is available to get started.

Bitbucket Pipelines is a cloud-native CI/CD tool so you never have to worry about provisioning or managing physical infrastructure, meaning more time focusing on other priorities.

jlqeBYvr37F2sk7yZVCISiJMim1Ris6QOMfL9HK5vIqzWdTHNcq-acWVGYHJMxTMVxwzpyKw9PFN6smSdH5RUiJR-t0mA7LXmWGd6VEk2ypPYiJyVobNwvaZaYOWLdAaVpkP2k2r

Integrations

Bitbucket pipeline provide integration to various tools used to test, scan and deploy different sort of applications in a plug and play fashion.

So for this integration, they provide pipes (A pipe is a custom Docker image for a container, which contains a script to perform a task. There are a bunch of available Pipes, but you can write your own too.) It is similar to the plugins in other CI/CD tools.

08Roh_PGur-wo0YUX_5Mr255I69MkRc4E7ftKKpjQBx7s8lZp34LrgUJo2B1_zdm1t1hOJh8y5DwbWxwarU52dCQIAJDKKRaYPw0jG8kBR0SqwWrnKt2_huLzJbzk7cGiSh8p6Gy

Deployments

Pipelines offers a robust set of deployment functionality that provides teams the confidence and flexibility to track your code from development through code review, build, test, and deployment all the way to production. 

For more sophisticated workflows you can create up to 10 environments to deploy to, and see what code is being deployed where via the deployment dashboard.

fsdAJ8hEPqvP-ax0DEIrqVpJkn2RtCwbE0CO8-vnT956KFzmr52nvQ-MMNUiCizfFVTt9shL7bRN8A4NEmgzKt_nsyl1ztD2wHLLLAhnzsfRJ1dkMTlSLJktA75OEDmMwDI3uonj

Increased visibility and collaboration

As we know, Atlassian provides various tools like Jira, confluence, etc which can be easily integrated with the pipeline which leads to an increase in visibility and collaboration.

For example, we can simply link Jira with the bitbucket pipeline. Along with that deployment details like which version or which build number is currently deployed on the server and other information regarding tasks, issues, etc can be easily visible from the Jira board.

1BXl2mMOMw6HPkQbyy7jm4kJkgEjrL1oE5UUhOlGEfWvM-EpnzkP4eztfy568MWQrGWtgzRi679e1THW0rjkBt9EZw5cb2yBCzwSvUrD4BI5MeM72kzxg9RNX3U9trOn1yzOhTmt

Pricing

Pipelines pricing is based on a simple, consumption-based model of build minutes used, and every Bitbucket plan includes build minutes.

Plan typeBuild minutes per monthFree50 minutesStandard2500 minutesPremium3500 minutesPricing model in Bitbucket pipeline

Create your first pipeline

I have a simple python flask application available here. I used this python application to test and deploy code to a server.

Firstly, we need to create a pipeline and push it to the repository. Or we can directly create a pipeline from the bitbucket interface in the pipeline section.

Also we need to enable the pipeline in the repository in the pipeline configuration.

This is simple bitbucket pipeline which run on each commit.

image: python:3.8

pipelines:
  default:
    - step:
        name: Test
        caches:
          - pip
        script:
          - python test.py
    
    - step:
        name: deploy to the server
        deployment: Production
        script:
          - pipe: atlassian/scp-deploy:0.3.3
            variables:
              USER: 'ubuntu'
              SERVER: '<server-ip>'
              REMOTE_PATH: '/home/ubuntu/app'
              LOCAL_PATH: 'main.py'

Bitbucket pipeline uses YAML to config the pipeline. It uses an image to run each step inside the docker container. Each step runs in a separate docker container to run the script. We also can use separate images for each step.

Here, in this pipeline, we use a docker image of python:3.8 to test and deploy a python application.

The above bitbucket pipeline will show following interface in bitbucket UI.

yK4-P344xiExIs1VJrn_evLecK91UuYMENx3eJ3g9S8ojgUzt18sUjJ40aAitcOEvgt1PQxVepaQyQItRdTIb0w9kre9IoRvye8zDDYjvsgfEO3yUDMOk6ELQ-QTCXOXsMysy19p

Some basic Configuration keywords

With a basic configuration, you can do things like write scripts to build and deploy your projects and configure caches to speed up builds. You can also specify different images for each step to manage different dependencies across actions you are performing in your pipeline.

A pipeline is made up of a list of steps, and you can define multiple pipelines in the configuration file.

In the following diagram provided below, you can see a pipeline configured under the default section. The pipeline configuration file can have multiple sections identified by particular keywords.

3FW9xbdQxwCkTX3m-nLJhhxwyn788M6QYPuSsvHe-T-DbMJ1qF5H4rfgV4oqIOYsDpEJOwMgDXlNnWlQPtPaCGAcbR96YoZ2ksDYD47IaSuq87ynajU8x_iN06jRUTUX9aVRyFeF

default – Contains the pipeline definition for all branches that don’t match a pipeline definition in other sections. The default pipeline runs on every push to the repository unless a branch-specific pipeline is defined.

branches – You can define branch-specific pipeline under branches section.

tags – Defines all tag-specific build pipelines.

pull requests – A special pipeline that only runs on pull requests initiated from within your repository. It merges the destination branch into your working branch before it runs.

custom – If we want to trigger a pipeline manually or from the bitbucket UI then we can use custom keywords in the steps.

Also there is much more things you can use in bitbucket pipeline, so you can use the reference below for that.

Conclusion

In this blog we learn what is bitbucket pipeline and hoe can we configure pipeline.

Bitbucket pipelines are very simple to create and configure. It’s just a two-way step to configure and enable pipelines, we can even use different templates based on our application and programming language.

References

https://support.atlassian.com/bitbucket-cloud/docs/get-started-with-bitbucket-pipelines/

https://bitbucket.org/product/features/pipelines


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK