Pipeline Variables in CI/CD

 

variable plays a very important role in overall release and build pipelines.

Variable is responsible for:- 

  • Variables provide a convenient method for incorporating/injecting critical data into various components of your pipeline.
  • Variables are employed to ensure that custom and shared data is present in multiple pipelines.
  • Define a value that can be subsequently utilized in your pipeline is the most prevalent application of variables.
  • Variables are mutable and are represented as strings. 

 

 

Type of Variables

 

 

 

 

Use Custom Variables

Custom Pipeline Local Variables

  • Go to Release pipe line, click Variable Tab at the top
    • Click your pipeline > Click last running Release > Click Edit Pipeline
    • Now click variable and click ‘Pipeline variables’ for custom variables
    • Click Add

 

 

  • Why we need custom variables
    • So to use that variable value across multiple environment as  dev and QA or multiple tasks 

 

 

  • Define and Use Custom Variable
    • Define a variable
    • Use above variable in Dev Environment 
      • Use by clicking Dev in Release pipeline
      •  

 

  • Reuse Pipeline Variable in different Environment with in same pipeline
    • Open Dev Pipeline in Edit Mode
    • Right click on Dev and Clone the environment
    • Rename as QA
    • Go to variable list now
      • Same variable is created for QA also
      • Just rename 

 

 

  • Custom Variable also works if you close your Pipeline as well
    • Click Releases on left and get option to clone

 

 

  • Import / Export Variables to different project or pipeline
    • Import / export option showing above, use that

 

  • The values of pipeline custom variable defined over here cannot be used in other pipelines. It will be only local to this pipeline okay.

 


Custom Global Variables (Variable Groups)

Use Case:  You are in the process of developing database pipelines and are utilizing the user ID and password of SQL Server. Currently, those are common values that you wish to transmit to Multiple distinct pipelines.

 

How? Somewhere created at centralized, level and then pass it to your task. using Variable Groups

 

We can do this by using variable groups. You can store value and secrets in variable groups. These values can be shared across multiple build or release pipelines.

 

 

Create Variable Groups (Global level)

  • DevOps > Repos > Library
  • Click Variable Group Button
  • If you want your password to not be visible to anyone. The best way is to keep it in a vault.
  • Click Save

 

 

Use Global Variables into you multiple pipelines

  • DevOps > Pipelines > Release > Edit your Pipeline 
  • Go to variable Tab > Go to Variable Groups Option > Click 
  • you can see list of variable Groups on Right Panel. select  Your Group Radio button
  • Select your environment
  • Click Link

 

On Variable groups window we can see these as normal variables as we click show more button

  • Now we can use this as normal variable in our pipeline
  • If variable name are common under multiple variable group, change variable name as we done before. 
    •  

 


Related Question