Configuring Environment Variable in Azure CI Pipeline

1 minute read

Do you want to create environment level variable for your Azure Build CI Pipeline and access them in your azure pipeline task? Example: If you are using nx monorepo and you want to skip the Nx Caching while building your project in Azure pipeline or your build machine then read this article to understand it.

New Variable Form

First go to your pipeline definition and select variable.

Submit New Variable Form

Add variable name with its default value and then submit.

Access Environment Variable in YML file

Prefix it with a dollar sign and enclose it in parentheses. For example: $(SKIP_NX_CACHE)

Access Environment Variable in Script

use environment variable syntax. Replace . and space with _, capitalize the letters, and then use your platform’s syntax for referencing an environment variable. Examples:

  1. Batch script: %SKIP_NX_CACHE%
  2. PowerShell script: ${env:SKIP_NX_CACHE}
  3. Bash script: $(SKIP_NX_CACHE)

Example Accessing Environment Variable in You Nx Monorepo CI Pipeline

pool:
  vmImage: 'ubuntu-latest'

trigger:
  - main

variables:
  CAN_SKIP_NX_CACHE: $[eq(variables['SKIP_NX_CACHE'], 'True')] # Reading CAN_SKIP_NX_CACHE environment variable.

steps:
    - script: node ./build.js $(SKIP_NX_CACHE) # Calling your build script with environment variable value.

While running new pipeline from azure portal. You can always select your variable and update its value to false or true that will be passed to your build pipeline.

Become full stack developer 💻

If you want to become full stack developer and grow your carrier as new software developer or Lead Developer/Architect. Consider subscribing to our full stack development training programs. We have All-Access Monthly membership plans and you will get unlimited access to all of our video courses, slides, source code & Monthly video calls.

  • Please subscribe to All-Access Membership PRO plan to access current and future angular, node.js and related courses.
  • Please subscribe to All-Access Membership ELITE plan to get everything from PRO plan. Additionally, you will get access to monthly live Q&A video call with Rupesh and you can ask doubts/questions and get more help, tips and tricks.

Your bright future is awaiting for you so visit today FullstackMaster and allow me to help you to board on your dream software company as a Developer,Architect or Lead Engineer role. 💖 Say 👋 to me!

Rupesh Tiwari

Comments