DEV Community

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

Posted on

6 3

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay