Azure DevOps Pipelines Variables

Share

Azure DevOps Pipelines Variables

In Azure DevOps Pipelines, variables play a crucial role in defining and controlling the behavior of your CI/CD (Continuous Integration/Continuous Deployment) pipelines. These variables can be used to store values that are utilized across different stages and jobs within your pipeline. Variables are often used for things like connection strings, authentication tokens, environment-specific settings, and more.

There are two main types of variables in Azure DevOps Pipelines:

  1. Pipeline Variables: These are defined at the pipeline level and are accessible across all stages and jobs within the pipeline. Pipeline variables are defined in the YAML file that defines your pipeline, usually at the top level. They can be set using the variables section.

    yaml
    trigger: branches: include: - main variables: myVariable: "Hello, World!" jobs: - job: Build steps: - script: echo $(myVariable)
  2. Job and Step Level Variables: These are defined within specific jobs or steps and are only accessible within that particular context. They can be set using the jobs and steps sections in your YAML file.

    yaml
    jobs: - job: Build steps: - script: echo $(Build.SourcesDirectory) # Predefined system variable - script: echo $(myJobVariable) # Job-level variable defined below displayName: "Echo Job Variable" - job: Deploy variables: myJobVariable: "This is a job-level variable" steps: - script: echo $(myJobVariable) displayName: "Echo Job Variable in Deploy Job"

Apart from these, you also have access to predefined system variables and environment variables.

Predefined System Variables: Azure DevOps provides a set of predefined variables that hold information about your pipeline, repository, and more. Examples include Build.ArtifactStagingDirectory, Build.SourceBranch, Agent.JobStatus, etc.

Environment Variables: Environment variables can be used to pass information to your scripts and tools during the execution of pipeline steps. These variables can be set explicitly in your YAML or derived from pipeline or system values.

To set pipeline variables dynamically based on conditions, you can use expression syntax within your YAML:

yaml
variables: dynamicVar: $[ condition ? 'value_if_true' : 'value_if_false' ]

Remember that variables in YAML pipelines are case-insensitive and support different syntaxes for variable interpolation, such as $(variableName) or ${{ variables.variableName }}.

Using variables in Azure DevOps Pipelines allows you to maintain flexibility and reusability while ensuring that sensitive data is not hard-coded in your pipeline configuration. They provide a way to customize and parameterize your pipeline’s behavior based on different environments and 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 *