Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Adding parameters in Azure DevOps pipelines examples Part 1

This is an example of how to use parameters in Azure DevOps Pipeline YAML configurations. To start with this I have added first parameters: in the YAML file configuration. Under it I have multiple parameters, to create basic string parameter 3 properties are required name, displayName and type as shown in A section. When you don't define default value (Section A and B), from the right side you can see input is mandatory and required.

If you want to provide multiple select values, use values property with array of list (Section C). Next if you want CheckBox, type will be boolean (Section D).

To use these all the parameters in the steps/script I am using placeholder ${{ }}. For example if there is name of parameter is stringText1 I will use ${{  parameters.stringText1 }} in the script.

When you try to run pipeline it popups and prompts for the values and options to select.

Microsoft Azure Pipelines yaml displayname type default values jobs steps stages run pipeline branch git string pool of images checkbox advanced options yml azure devops.png

As you can see after inputting all the parameter values and running pipeline I see the Job/Step output on the console, check the executed PowerShell command outputs. You will see all the provided values from parameters.

Reference Document: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/runtime-parameters?view=azure-devops&tabs=script

Microsoft Azure Devops Pipeline PowerShell script linux windows parameters Azure Devops parameters yaml yml script basic script configuration.png

Here is complete code. Download this Azure_DevOps_parameters_example_pipline.yaml here or it is also available on github.com.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- none

pool:
  vmImage: ubuntu-latest

parameters:
  - name: stringText1
    displayName: string Text Example1
    type: string

  - name: stringText2
    displayName: string Text Example2
    type: string
    default: ' '

  - name: image
    displayName: Pool Images
    type: string
    values:
      - windows-latest
      - ubuntu-latest

  - name: checkBox
    displayName: checkbox ?
    type: boolean
    default: false

stages:
  - stage: build
    jobs:
      - job: Parameters
        pool: 
          vmImage: ${{ parameters.image }}
        steps:
          - powershell: |
              Write-Host "String Text Example1: ${{ parameters.stringText1 }}"
              Write-Host "String Text Example2: ${{ parameters.stringText2 }}"
              Write-Host "image: ${{ parameters.image }}"
              Write-Host "image: ${{ parameters.checkBox }}"

Useful Articles
Azure DevOps Enable creation of classic build release pipelines grayed out
DevOps Part 1.1 SCM Git - Create Resource Group in Microsoft Azure
DevOps Part 1.2 SCM Git - Create Virtual Network (vNET) in Microsoft Azure
Hashicorp Terraform map and object inside module and variable example
Terraform one module deploy null or multiple resources based on input
Terraform A reference to a resource type must be followed by at least one attribute access, specifying the resource name
Terraform fore_each for loop filter with if condition example
Terraform remote-exec provisioner with ssh connection in null_resource
Terraform count vs for_each for examples with map of objects
Terraform one module deploy null or multiple resources based on input (nested for loop)

Go Back

Comment

Blog Search

Page Views

11579753

Follow me on Blogarama