HandsOn – Azure Pipelines with YAML
Last week I published an article about the new capabilities of Azure DevOps pipelines (with YAML). As I promised we continue this topic on Today. Although the last week provided documentation contains the most important information, I feel I should show you how it works in the real life. Why? Because the documentation is not the best for that….as usual.
Scenario for today: Create a basic NodeJS project which is stored on GitHub repository. This NodeJS project is a simple script which will be executed by Azure DevOps pipeline via a YAML file.
After this “episiode” you are able to execute automatically any of your existing NodeJs script or solution in Azure DevOps pipeline. This means you will have a CICD-like solution from your existing NodeJS solution. It’s cool, isn’t it?
Additionally, I’ve decided to create a video guide for this article, which helps you to see the whole flow, step-by-step. You can find it below.
Step 1: Create a GitHub repository for your code
As usually the first step to create a private or public repository on GitHub. This is a basic steps and I assume you can do it. 🙂
Step 2: Write your basic code with YAML file
- Next step after GitHub repository creation to clone the repository to the local computer. For this I use Visual Studio code.
- Open your cloned repository and start to create the NodeJS solution.
- Create the following 3 files:
- package.json: This contains the project related information and the required package list for your solution.
- startPilepine.js: This is our very basic existing NodeJS solution. Later on you can replace it to your existing solution.
- pipeline.yaml: According to this file the Azure DevOps will build the pipeline. So this file contains the pipeline related information such as environment settings, pipeline steps, triggers.
- Finally, test our solution locally.
You can find the content for files here: https://github.com/cloudsteak/YAML-pipeline
Step 3: Push our solution to GitHub
When our solution is ready to use, we should push to our newly created GitHub repository. Here there is no any special steps, merely you should commit and push the changes.
Step 4: Create Azure DevOps project
Our solution is located on GitHub, so we are almost done. Now we create a project in Azure DevOps where we will create our pipeline. For this you should follow the following steps:
- Login to Azure DevOps. Open this links: https://azure.microsoft.com/en-us/services/devops/ and click on Sign in to Azure DevOps link.
- Choose your Organization or create a new one.
- Inside the selected organization click on New Project button, top right corner of the screen.
- In the Create new project window enter the Project name, Description.
- Select the required visibility of this project; Public or Private. Be careful, this is not equal with the visibility of your GitHub repository.
- Inside Advanced section the Version control should be Git.
- If everything is ok, click on Create button
Step 5: Create pipeline
- Inside the newly created Azure DevOps project go to Pipelines section (left side menu)
- Then click on Create Pipeline button, middle of the screen
- At next screen select the GitHub (YAML) from the list
- Next steps to Select a repository from GitHub.
If you are not connected from Azure DevOps to GitHub yet, you have to do it here.
If you are connected from Azure DevOps to GitHub you can see the list of your repositories and you can choose the required one. - When you select the required repository you can see the Approve & Install Azure Pipelines window where you have to grant access to your repository to Install pipelines.
- After this, you can start the configuration of pipeline. For this please choose the Existing Azure Pipelines YAML file options at the Configure your pipeline screen.
- Then a sidebar appears on the right side of the screen (Select an existing YAML file) where you must select the YAML (files from the required branch) which contains the pipeline related information. Select the pipeline.yaml then click on Continue button.
- Accordingly the pipeline has been created after some seconds. Here you can Run immediately it or just Save.
From this you have a Pipeline from a YAML file.
Step 6: Execute the pipeline
Great, we have a pipeline. To execute this pipeline we have now 2 (two) options:
- Run manually from Azure DevOps
- Navigate to Azure DevOps > Your organization > Your project > Pipelines > Pipelines > All
- Click on name of your YAML based pipeline
- Finally click on Run pipeline
- Triggered by GitHub push
- Modify your code your code (in Visual Studio Code)
- Then push the modification to GitHub repository
- This will trigger the pipeline to start to execute.
Step 7: Check result
This is a very simple thing.
- Navigate to Azure DevOps > Your organization > Your project > Pipelines > Pipelines > All
- Click on name of your YAML based pipeline
- Select the required Run from the list
- At the new screen click on Job node_13_x
- Here you can see the details of execution
We are done with the scope of scenario. 🙂
Last but not least. You can find the video, if you like the video content better:
Create Azure Pipeline from YAML
CloudSteak on Twitter ...