Azure DevOps Conditions

Share

   Azure DevOps Conditions


In Azure DevOps, conditions are used to control the flow of your pipeline or define when specific tasks or jobs should run. Conditions allow you to create flexible and customizable pipelines that respond to various situations and criteria. Here are common use cases and types of conditions in Azure DevOps pipelines:

  1. Trigger Conditions:

    • Branch Filters: You can specify branch filters to control when a pipeline should be triggered. For example, you can set up a condition to trigger a pipeline only when changes are pushed to specific branches (e.g., main, feature branches).
    yaml
    trigger: branches: include: - main - feature/*
    • Path Filters: Use path filters to trigger a pipeline when changes occur in specific directories or files. This is useful for multi-repo pipelines or monorepo scenarios.
    yaml
    trigger: paths: include: - src/*
  2. Agent Conditions:

    • Agent Pool and Demands: You can specify conditions based on the agent pool or custom agent demands. For example, you can ensure that a job runs only on agents with specific capabilities.
    yaml
    pool: name: MyAgentPool demands: - npm
  3. Stage and Job Conditions:

    • Dependency Stages: You can set conditions on stages to control whether they run based on the success or failure of previous stages. This is useful for defining deployment stages that should only run if the build is successful.
    yaml
    - stage: Deploy dependsOn: Build
    • Job Dependencies: Similarly, you can set job dependencies within a stage. Jobs with dependencies will run only if the specified conditions are met.
    yaml
    jobs: - job: Build - job: Test dependsOn: Build
  4. Variable Conditions:

    • Custom Variables: You can define custom variables in your pipeline and use their values to control conditions. For example, you can set up a condition based on a variable’s value.
    yaml
    variables: myVar: true jobs: - job: MyJob steps: - script: echo This job runs if myVar is true condition: eq(variables['myVar'], 'true')
  5. Expression-Based Conditions:

    • Expressions: Azure DevOps pipelines support expressions for more complex conditions. You can use expressions to combine conditions, evaluate variable values, and perform logical operations.
    yaml
    jobs: - job: MyJob steps: - script: echo This job runs if both conditions are met condition: and(succeeded(), eq(variables['myVar'], 'true'))
  6. Time-Based Conditions:

    • Schedules: You can schedule pipeline runs using cron expressions. This allows you to automate pipeline execution at specific times or intervals.
    yaml
    schedules: - cron: "0 0 * * *" displayName: Daily build

These are some of the common conditions and scenarios in Azure DevOps pipelines. Conditions help you create pipelines that are responsive to changes, adaptable to different environments, and efficient in resource utilization. They play a crucial role in defining the behavior and logic of your CI/CD workflows.

Demo Day 1 Video:

You can find more information about DevOps in this DevOps Link

 

Conclusion:

Unogeeks is the No.1 IT Training Institute for DevOps Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on  DevOps here – DevOps Blogs

You can check out our Best In Class DevOps Training Details here – DevOps Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook:https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *