Azure DevOps (CICD Pipeline) - Part 1
In this article we will learn how to setup Azure CI Pipeline to trigger build on code commit and generate artifact which we can use then to host and run the app.
You must have azure account to access the devops portal/board. You can login with you github account to have free access. On sign up, you create organization and then inside that organization you start creating multiple projects and setup CICD and azure board for your projects.
https://azure.microsoft.com/en-us/services/devops/boards
If you are using free account then on running pipeline, you might get error "No hosted parallelism has been purchased or granted", so Microsft now does not allow running pipeline free by default, so for that you can send email on by providing organization name and your project details: "azpipelines-freetier@microsoft.com".
Here - "sarajeevraj" is my organization name and inside that, I can create multiple projects and manage my work items(tickets) and pull requests(PR-code review).
Create azure repository + sample code app/code push to repository:
- Login to Azure DevOps portal and create new project.
- Open project and navigate to repository file and copy the clone URL which you can use with your IDE to clone the repository on your local system and commmit some code.
- After successful clone, create sample app and push/code the code. (In this case, I have created .net core web application for this demo).
Now we have sample app available with repository created, so lets setup CI pipeline:
To create pipeline with publish artifacts:
Go to inside project, and from left panel, click pipeline and create pipeline.
Select code source:
Select project for the pipeline:
Select framework used for your project:
Once you select, it by default generate pipeline configuration in yaml which contains all the required task/steps to download dependent nuget package, compile code, test your project code in asp.net core, refer below :
Addition to this, we need to add one more - task to publish the code(called artifacts), so that on successful pipeline run, it will publish your code as artifact which you can verify/download/push-to-your-any-server manually or using CD(release pipeline).
So to add publish - task to this yaml pipeline configuration, go the end of this file (keep curser there) and then from right side (show assistant option) search for publish artifact task and select that and configure:
Put artifact name and add. Here I also changed the path(so if you refer build task in your yaml file that contains this path and I used same here to publish artifacts):
If you want to update again any task, you can click on setting and it will open again the visual (task assistant option):
Now save your pipeline and post that you can start seeing your pipeline:
Now for test, run your new pipeline manually and verify your published artifacts:
While pipeline running, you can validate the full job status:
Once pipeline is completed, you can see the published artifacts. To know all the history of pipeline run, go to pipeline you are looking for and there you will find all the run history and then click on specific history which you want to check and there you will find the publish artifacts:
Now, I want to trigger my CI pipiline automatically on code commit/push to my Azure repository app created and to do that, go to pipline you just created and navigate to trigger tab, and change the trigger option:
If you are in YAML view then, to get trigger tab: edit you pipeline and then either you will find trigger tab on same screen, otherwise choose this option from three dot(…):
So now, whenever you push/commit code to master branch, your pipeline will start automatically.
Categories/Tags: azure devops~cicd