Is there any way to read input paramaters or variables from csv files in azurepipeline?

vivsar 6 Reputation points
2021-12-26T11:26:53.007+00:00

I am looking for a solution in azuredevops pipeline to read runtime paramater values or variables directly from csv files where user can input the values and commit to the csv file holding repository and from where the pipeline can be triggered. I have number of runtime paramaters set in the azurepipeline now and converting those paramaters to variables using the pipeline runtime task and then using those variables in the further script tasks.

So looking for a solution where user can directly input the variable values in a csv file and pipeline can fetch those values and execute those script tasks.

The advantage I am looking here is that, the csv file can have multiple rows for each variables and user can have the modification only to the specific variable where the modification required and rest of the column values will be available for next execution.

Below is the azurepipeline yaml i am using and here you can see the paramater section with mutiple values to have runtime paramaters and again i have task to create the corresponding variables. this making the pipeline complex and too lengthy. Also i want to add multiple options to add to those paramaters and would like to have the values stored and so that user can modify only the required paramater value when it needs updation for next time. So looking for a way to read these parameters/variables from a file as per user input.

parameters:
- name: subscription
  type: string
  default: 'MySubscription'
- name: resourceGroup
  type: string
  default: 'Myrg'
- name: AlertRuleName
  type: string
  default: '' 
- name: appname
  type: string   
- name: alertquerylist
  type: object
  default:
  - <query1>
  - <query2>
- name: alertDescription
  type: string
  default: ''     
- name: frequencyInMinutes
  type: number
  default: 1  
- name: timeWindowInMinutes
  type: number
  default: 1    
- name: severity
  type: number
  default: 1
  values:
    - 0
    - 2
    - 3 
- name: operator
  type: string
  default: 'GreaterThanOrEqual'
  values:
  - GreaterThanOrEqual
  - LessThan
  - Equals
  - NotEquals
  - GreaterThan
  - GreaterThanOrEqual
  - LessThan
- name: threshold
  type: number
- name: autoMitigate
  type: boolean
  default: false
pool:
  name: mypool 
stages:
- ${<!-- -->{ each query in parameters.alertquerylist }}: 
  - stage: BuilD_ARM_LogSearch_Count
    displayName: 'Build and validate Query Based Alert for aggregator Count'
    variables:
      - group: alert-config
      - name: query
        value: ${<!-- -->{ query }}
      - name: AlertRuleName
        value: ${<!-- -->{ parameters.AlertRuleName }}        
    jobs:
    - job: Validate_Alert 
      steps:
      - bash: |
          frequencyInMinutes=${<!-- -->{ parameters.frequencyInMinutes }}
          echo "##vso[task.setvariable variable=frequencyInMinutes]$frequencyInMinutes"
          timeWindowInMinutes=${<!-- -->{ parameters.timeWindowInMinutes }}
          echo "##vso[task.setvariable variable=timeWindowInMinutes]$timeWindowInMinutes"
          evaluationFrequency=${<!-- -->{ parameters.evaluationFrequency }}
          echo "##vso[task.setvariable variable=evaluationFrequency]$evaluationFrequency"
          windowSize=${<!-- -->{ parameters.windowSize }}
          echo "##vso[task.setvariable variable=windowSize]$windowSize"
          severity=${<!-- -->{ parameters.severity }}
          echo "##vso[task.setvariable variable=severity]$severity"
          operator=${<!-- -->{ parameters.operator }}
          echo "##vso[task.setvariable variable=operator]$operator" 
          threshold=${<!-- -->{ parameters.threshold }}
          echo "##vso[task.setvariable variable=threshold]$threshold" 
          autoMitigate=${<!-- -->{ parameters.autoMitigate }}
          echo "##vso[task.setvariable variable=autoMitigate]$autoMitigate"
          alertDescription=${<!-- -->{ parameters.alertDescription }}
          echo "##vso[task.setvariable variable=alertDescription]$alertDescription"
          appname=${<!-- -->{ parameters.appname }}
          echo "##vso[task.setvariable variable=appname]$appname"                
        name: Resolve_variable      
#      - ${<!-- -->{ each item in parameters }}:
#         - bash: |
#               echo "##vso[task.setvariable variable=${<!-- -->{ item.key }}]${<!-- -->{ item.value }}"
#           displayName: "Create Variable ${<!-- -->{ item.key }}"  
      - task: replacetokens@3
        inputs:
          rootDirectory: '$(System.DefaultWorkingDirectory)/'
          targetFiles: '$(System.DefaultWorkingDirectory)/logsearch-numberofresult/*.json'
          encoding: 'auto'
          writeBOM: true
          actionOnMissing: 'warn'
          keepToken: false
          tokenPrefix: '#{'
          tokenSuffix: '}#'
          useLegacyPattern: false
          enableTelemetry: true
      - task: AzureCLI@2
        displayName: "create"
        inputs:
          azureSubscription: ${<!-- -->{ parameters.subscription }}
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: 'az group deployment create --resource-group ${<!-- -->{ parameters.resourceGroup }} --template-file $(System.DefaultWorkingDirectory)/logsearch-numberofresult/numofresult_template.json --parameters $(System.DefaultWorkingDirectory)/logsearch-numberofresult/numofresulparam.json'
Azure DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
254 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,805 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Dave Patrick 426K Reputation points MVP
    2021-12-26T19:16:30.627+00:00

    The product group for Azure DevOps / TFS actively monitors questions over at
    https://developercommunity.visualstudio.com/report?space=21&entry=problem
    https://developercommunity.visualstudio.com/report?space=22&entry=problem

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments