Azure DevOps YAML Variables

Share

Azure DevOps YAML Variables

In Azure DevOps, YAML pipelines allow you to define your CI/CD (Continuous Integration/Continuous Deployment) pipelines as code using YAML syntax. You can also define variables within your YAML pipelines to make them more dynamic and configurable. YAML variables in Azure DevOps provide a way to parameterize your pipeline configuration and make it easier to reuse and customize.

Here’s how you can work with YAML variables in Azure DevOps pipelines:

Defining YAML Variables:

You can define YAML variables at different levels of your YAML pipeline, including at the pipeline level, stage level, or job level. Here’s how to define YAML variables:

  1. Pipeline-level Variables:

    • Define pipeline-level variables at the top of your YAML file under the variables section.
    • These variables are available to all stages and jobs within the pipeline.
    yaml
    variables: myVar: 'myValue'
  2. Stage-level Variables:

    • Define stage-level variables within a specific stage.
    • These variables are available to all jobs within the stage.
    yaml
    stages: - stage: MyStage jobs: - job: MyJob steps: - script: echo $(myVar) displayName: 'Print Variable' variables: myVar: 'myValue'
  3. Job-level Variables:

    • Define job-level variables within a specific job.
    • These variables are only available within that job.
    yaml
    jobs: - job: MyJob steps: - script: echo $(myVar) displayName: 'Print Variable' variables: myVar: 'myValue'

Using YAML Variables:

Once you’ve defined YAML variables, you can use them within your pipeline configuration. You can reference variables using the $(variableName) syntax.

Example of using a variable within a script step:

yaml
jobs: - job: MyJob steps: - script: echo $(myVar) displayName: 'Print Variable'

Variable Groups:

In addition to defining variables directly in your YAML file, Azure DevOps also allows you to create variable groups. Variable groups are a way to store and manage variables separately from your pipeline YAML. You can link variable groups to your YAML pipeline, and the variables within those groups can be referenced in your YAML file.

Environment Variables:

Azure DevOps also provides predefined environment variables that are automatically available in your pipelines. These variables provide information about the environment in which the pipeline is running and can be useful for customization.

Here’s an example of using an environment variable:

yaml
jobs: - job: MyJob steps: - script: echo $(AGENT.OS) displayName: 'Print Agent OS'

In this example, AGENT.OS is an environment variable that contains the name of the agent’s operating system.

YAML variables in Azure DevOps provide flexibility and reusability in your pipeline configurations, allowing you to parameterize your pipelines and make them more adaptable to different scenarios.

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 *