DEV Community

Cover image for BulkRun Powershell Script for Azure Pipelines
Antonio Di Motta
Antonio Di Motta

Posted on

BulkRun Powershell Script for Azure Pipelines

Azure Devops provides a great UI for managing and run the pipelines, but sometimes we need to run it manually, just to reuse the deployment logic or when its required to run many of them.

To accomplish this job, I created a simple powershell script to run a set of pipeline programmatically by using the Azure Devops rest API and it requires a Personal Access Token

Example

# Step 1: Create the pipeline on Azure Devops with following yaml code. Below an example with parameters. parameters: - name: name displayName: "Name" type: string - name: surname displayName: "Surname" type: string pool: vmImage: ubuntu-latest steps: - script: echo Hello ${{ parameters.name }} ${{ parameters.surname }} displayName: 'Run a one-line script' 
Enter fullscreen mode Exit fullscreen mode
# Step 2: Create a pipeline definition file (pipetorun.csv) with the information to run an ado pipeline for each row. # The definitionid is the definitionid of Azure Devops pipeline # Branch is the pipeline's branch. # Parameters are defined as a dictionary (key=value separate by semicolon, key is equal the pipeline parameter name) definitionid,name,branch,parameters 12,hello,main,name=Alan;surname=Turing 12,hello,main,name=Clude;surname=Shannon 12,hello,main,name=Tim;surname=Berners-Lee 12,hello,main,name=Edsger;surname=Dijkstra 12,hello,main,name=Leslie;surname=Lamport # Step 3: Run five pipeline by using the script and the defintion file. (How to create a PAT ) .\BulkRun.ps1 -PAT personal-access-token -File .\pipetorun.csv 
Enter fullscreen mode Exit fullscreen mode
# Result hello inProgress on main -> https://dev.azure.com/dimotta/demo/_build/results?buildId=119 hello inProgress on main -> https://dev.azure.com/dimotta/demo/_build/results?buildId=120 hello inProgress on main -> https://dev.azure.com/dimotta/demo/_build/results?buildId=121 hello inProgress on main -> https://dev.azure.com/dimotta/demo/_build/results?buildId=122 hello inProgress on main -> https://dev.azure.com/dimotta/demo/_build/results?buildId=123 
Enter fullscreen mode Exit fullscreen mode

Image description

The BulkRun script code is available here

Top comments (0)