Writing YAML and running pipeline
Date published:
This blog will show how to write a YAML file using the Azure DevOps pipeline with two examples. Azure Pipelines automatically builds and tests code in a source control repository like Git. It combines continuous integration (CI) and continuous delivery (CD) to test and build your code into a production environment. Microsoft Docs
A pipeline is from stages, jobs and tasks. Usually, an azure-pipelines yaml file is created at the root of your repo. Here is a video showing the basics of a pipeline. Key concepts for new Azure Pipelines
- Stages - This can contain several stages in a pipeline file
- Jobs - Each stage can have multiple jobs
- Steps - For each job, it can have a series of steps
Each pipeline has the following information.
- Name - This is the branch used
- Trigger - Manually, Branch or pipeline
- Pool - This is the agent (Microsoft hosts or self-hosted agent)
- Stages - Enabled continuous deployment/delivery
- Jobs - Can contain a pool
- Environment - Can contain security, resources, approval/check and tracks the deployment job
- Steps - showing steps for each job like previously described
- Tasks - This can be in the form of action
Example1-Displaying text
To get started with the first pipeline, you will need to import the Github URL https://github.com/nicholaschangIT/DevOpsMC and go to Part04CICD of the section for the pipeline file used. Go to the Azure DevOps portal and create a project, and under repo, click on the file, and select import a repository.
-main
pool:
vmImage: ubuntu-latest. - (Name of the Pool)
stages:
-stage: A
jobs:
-job: A1.
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script
This first stage has one job called A1 with a step that displays text.
-stage: B
dependsOn: [] #Will - (This do not dpeend om anything )
jobs:
-job: B1
steps:
-script: |
echo Another hello
echo From here!
displayName: 'Run a multi-line script'
This second stage does not depend on anything and contains a job and displays text
like the previous step, except this one will echo another word.
- stage: C
dependsOn:
- A
- B
jobs:
- deployment: C1
displayName: C1 deploy
environment: Test
strategy:
runOnce:
deploy:
steps:
- script: echo Running in the Test environment as deployment job
displayName: 'Test based stage'
In stage C, it will depend on A and B before running the C1 deploy job.
It used an environment called test that has a step too.
- stage: D
jobs:
- deployment: D1
displayName: D1 deploy
environment: QA
strategy:
runOnce:
deploy:
steps:
- script: echo Running in the QA environment as deployment job
displayName: 'QA based stage.'
The stage will run in another environment called ‘D1 deploy’ with a step before showing the display name.
Before you run the pipeline, you will need to add two environments to your azure DevOps pipeline. When running the pipeline, both stages A and B are parallel to each other. Stage C will depend on both A and B stages.
The above shows an overview of the pipeline completed.
Example 2 Building Python Application
In this second example, I will be deploying a Python sample application. Go to the pipeline tab, select Github repo as one of the repositories, and find your repo https://github.com/Microsoft/python-sample-vscode-flask-tutorial. I would recommend going to the link and forking the repo on your Github account.
In this stage, authenticate to Github and install the Azure pipeline. Click on Approve and install
Once installed and completed, it will direct back to Azure DevOps, then clicks on the python package to start configuring your pipeline.
Review the yml file and change the python version 3.5 to 3.6 as the version reaches the end of life. Click on save and run to start building the pipeline.
Further reading