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
- Microsoft predefined variable
- custom variable
- Local to respective pipeline
- Values can be passed and used in the pipeline task
- Environmental scope can be set at the variable levels.
- Variable values can be kept secret.
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
- Use by clicking Dev in Release pipeline
- Define a variable
- 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
- Same variable is created for QA also
- Custom Variable also works if you close your Pipeline as well
- Click Releases on left and get option to clone
- 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.