How to Create a Pipeline in Azure DevOps: Step-by-Step Guide
To create a pipeline in Azure DevOps, go to your project, select
Pipelines, then click New pipeline. Follow the wizard to connect your code repository, choose a pipeline template, and configure the build and deployment steps.Syntax
Creating a pipeline in Azure DevOps involves these main parts:
- Repository: Where your code lives (e.g., GitHub, Azure Repos).
- Pipeline YAML file: Defines the steps to build, test, and deploy your app.
- Pipeline UI: The Azure DevOps interface to create and manage pipelines.
yaml
trigger: - main pool: vmImage: 'ubuntu-latest' steps: - script: echo Hello, Azure DevOps! displayName: 'Run a one-line script'
Example
This example shows a simple pipeline YAML that runs a script on every push to the main branch.
yaml
trigger: - main pool: vmImage: 'ubuntu-latest' steps: - script: echo Hello, Azure DevOps! displayName: 'Run a one-line script'
Output
Run a one-line script
Hello, Azure DevOps!
Common Pitfalls
Common mistakes when creating pipelines include:
- Not setting the correct branch in
trigger, so the pipeline does not run. - Using incorrect YAML indentation, which causes errors.
- Forgetting to select the right agent pool, leading to build failures.
- Not committing the YAML file to the repository, so Azure DevOps cannot find it.
yaml
trigger: - main pool: vmImage: 'ubuntu-latest' steps: - script: echo Hello displayName: 'Run script'
Quick Reference
Tips for creating Azure DevOps pipelines:
- Always commit your
azure-pipelines.ymlfile to your repo root. - Use
triggerto specify branches that start the pipeline. - Choose the right
vmImagefor your build environment. - Test your pipeline with simple scripts before adding complex steps.
Key Takeaways
Create pipelines in Azure DevOps by connecting your repo and adding a YAML file.
Use the
trigger keyword to control when the pipeline runs.Indent YAML correctly to avoid syntax errors.
Select the appropriate agent pool for your build environment.
Commit your pipeline YAML file to the repository root for Azure DevOps to detect it.