Configuring your Azure DevOps Pipelines in a YAML file
To configure Azure Pipelines in a YAML file that exists alongside your code, follow these steps:
Steps to Configure Pipelines in a YAML File.
1. Create a YAML File
Locate the Source Code Repository: Open your source control repository (e.g., GitHub, Azure Repos, Bitbucket).
Add a YAML Pipeline File: Create a
.ymlfile in the.github/workflows/directory for GitHub or directly in the.azure-pipelines/directory for Azure Repos.Example path for Azure Repos:
/.azure-pipelines/pipeline.ymlDefine the Pipeline: Use YAML syntax to define your pipeline as shown below.
2. Structure of YAML Pipeline
A simple YAML pipeline includes:
Pipeline: The overall pipeline definition.
Stages: Different phases like Build, Test, Deploy.
Jobs: Individual tasks within a stage.
Steps: Individual actions executed within a job.
3. Example YAML Pipeline
xxxxxxxxxx351# Define the pipeline2pipeline3 nameBuild and Deploy App4
5# Define the stages6stages7stageBuild8 jobs9jobBuildJob10 pool11 vmImage'ubuntu-latest' # Specify a VM image12 steps13script14 echo "Building application"15 dotnet build16stageTest17 dependsOnBuild18 jobs19jobTestJob20 pool21 vmImage'ubuntu-latest'22 steps23script24 echo "Running tests"25 dotnet test26stageDeploy27 dependsOnTest28 jobs29jobDeployJob30 pool31 vmImage'windows-latest'32 steps33script34 echo "Deploying application"35 az webapp up --resource-group myResourceGroup --name myAppName --sku B14. Place the YAML File
For GitHub, place the YAML file in
.github/workflows/.
Example: /.github/workflows/pipeline.yml
For Azure Repos, place the YAML file in
.azure-pipelines/directory.
Example: /.azure-pipelines/pipeline.yml
5. Link YAML Pipeline to Source Code
Push the YAML file to Source Control: Commit and push the YAML file alongside your code.
Trigger the Pipeline: Azure Pipelines or GitHub Actions will automatically pick up the YAML file in the specified directory.
Benefits of Using YAML Pipelines Alongside Code
Version Control: YAML files are versioned alongside the code, providing traceability and change management.
Consistency: Pipelines are defined as code, ensuring consistency across environments.
Portability: YAML files can be reused across different projects and repositories.
Summary
By configuring Azure Pipelines in a YAML file that exists alongside your code, you maintain a clean separation of pipeline configurations and application code, ensuring scalability and automation.






















Leave a Reply