Continuous Integration and Continuous Deployment/Delivery (CI/CD) is a software development practice in which your code remains in a central repository where the developers can merge their code and they can automate their software development process such as building, testing, deploying your code to the respective staging or production environment. The main goal of CI/CD is to deploy your code faster, safer and easier to the respective environment.
CI/CD Pipeline may sound like a complex technique, but it just contains a sequence of steps that should be run in an order to deliver a new version of the respective product. Without CI/CD Pipeline, the developers need to do these steps manually which reduces productivity. And also, it’s 2020, We need to automate several kinds of stuff to increase our productivity and one of my favorites is CI/CD Pipeline.
Azure DevOps
Azure DevOps is a cloud service that allows you to plan work, collaborate on code development, build and deploy applications. Most of the operations in Azure DevOps can be done at ease. It is completely free for projects which are in GitHub. There are many useful services provided by Azure DevOps such as,
- Repos
- Pipelines
- Boards
- Test Plans
- Artifacts
In this blog, we will explore Azure Pipelines where it makes the deployment process safer, easier and faster.
Azure Pipelines
It follows CI/CD technique that you can use to automatically build, test and deploy your code project and make it available for other users. And also, it supports many languages such as Python, Java, JavaScript, PHP, Ruby, C#, C++ and Go.
It can be integrated with GitHub, GitHub Enterprise, Azure Repos Git & TFVC, Bitbucket Cloud, and Subversion. For using it, you need An Organization in Azure DevOps and your source code should be in a version control system. To know how to create an organization in Azure DevOps, please visit this link.
There are several reasons to opt for it such as,
- Increases Code Coverage
- Build, test and deploy your code at ease
- Make every feature as release ready
- Run Automated Tests
- Push code to Production as pushing to a staging environment.
How to Build a CI/CD Pipeline in Azure DevOps?
Basically, to build a CI/CD pipeline, you need to have your project in a version control system. Let’s take a scenario where you have your source code in GitHub and you want to build a respective CI/CD Pipeline for a .NET Project.
Continuous Integration
STEP 1: Go to the Marketplace section and search for Azure Pipelines. As you can see, it’s free for public and private repositories. If you want to run parallel jobs, then it’s 40$ per month.
STEP 2: Click Install it for Free and select the repositories to install azure pipelines or you can install it for all the repositories in GitHub.
After selecting the respective project, click Save. In this scenario, we are going to install it for the Dapper Repository.
STEP 3: Once you click Save, it will be redirected to a login page where you need to enter your respective credentials and click Sign In.
STEP 4: Azure DevOps consists of organizations and each organization has several projects. In this step, we are going to create an organization and a project for this respective repository. Click Create a new Organization.
Mention the organization name and the project name. Here I have mentioned the organization name as PersonalOrganization-Dev and the project name as DapperConsoleApp. You can set the project visibility as Public or Private based upon your requirements. Then Click Continue
STEP 5: It will be redirected to the Azure DevOps portal. Select the respective Project.
STEP 6: The next step is the configuration. It will try to detect the type of your project and it will display the respective pipelines. In this scenario, we are going to select ASP.NET pipeline.
STEP 7: An YAML (Yet An Another Markup Language) config file will be created to define your pipeline config. Just click Save and Run. So, the CI build will be up and running. The first part is done by integrating your code with the respective Azure DevOps Pipeline.
Continuous Deployment
After building your code, you need to deploy it to the respective environment or else say you need a notification to teams or slack, etc, as your build has been succeeded. To that respective functionality follow the below steps,
STEP 1: Go to the Releases section and click New Pipeline
STEP 2: It has some predefined templates. You can deploy your apps to Azure App Service or any other deployment service. In this scenario, we are going to select an Empty Job.
STEP 3: In the respective diagram, select Add an Artifact and choose the respective project. And then click Add.
STEP 4: In the next step, we are going to create a set of tasks in the respective stage. Below Stage 1, you would be able to see 1 job, 0 task click on the link and it will open a window where you can define your tasks. In this scenario, we are going to define a PowerShell script as a task to get notified me as the build has been succeeded.
STEP 5: Click Add Task and Select PowerShell Script. You can just create your script and click Save.
That’s it You have built a CI/CD pipeline for your respective project. And also make sure you have enabled Continuous Deployment Trigger.
Conclusion
In this blog, we have made a CI/CD pipeline for the project which is present in GitHub. You can also create CI/CD pipelines, which are present in any other version control at ease. Basically, must define your pipeline config file(azure-pipelines.yml) and once it is done, you don’t have to worry about the deployment of your project.
There are many tools available for CI/CD, but the Azure DevOps makes it easier, safer and faster for code, build, test and deploy your projects to the respective environment. I hope in this blog, you’ll get an idea of building a CI/CD Pipeline.
Happy Coding!
Cheers! 🙂