How can I create multiple pipelines in Microsoft Azure DevOps by calling objects from single or multiple csv files?
How can the script pick up blank space from one of the excel columns? For example Folder Path
This is what I have so far.
Import-Csv -Path "C:\Users\*******\Downloads\excel\notes.csv"
$pipelineName = $pipelineVariables.name
$pipelineFolderPath = $pipelineVariables.FolderPath
$pipelineDescription = $pipelineVariables.Description
$pipelineRepostiory = $pipelineVariables.Repository
$pipelineBranch = $pipelineVariables.Branch
$pipelineYamlPath = $pipelineVariables.YamlPath
az pipelines create --name $pipelineName --folder-path $pipelineFolderPath --description $pipelineDescription --repository $pipelineRepostiory --branch $pipelineBranch --yml-path $pipelineYamlPath
The value for variables.
$pipelineName = $pipelineVariables.name
$pipelineFolderPath = $pipelineVariables.FolderPath
$pipelineDescription = $pipelineVariables.Description
$pipelineRepostiory = $pipelineVariables.Repository
$pipelineBranch = $pipelineVariables.Branch
$pipelineYamlPath = $pipelineVariables.YamlPath
Name : test-ci
FolderPath : build
Description : test ci pipeline
Repository : https://dev.azure.com/******/*****/_git/******
Branch : prod
Yaml Path : ./yaml/build.yml
This is the error message that I receive.
az : ERROR: argument --folder-path: expected one argument
At line:1 char:1
+ az pipelines create --name $pipelineName --folder-path $pipelineFolde ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR: argument...ed one argument:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
This is my csv file
You can use -Delimiter ","
not ;
for csv import
.
In addition, please also add --project
for your az pipelines create
command.
Use command to login: echo PAT | az devops login --organization https://dev.azure.com/orgname
.
With below PowerShell script:
# Import CSV file
$csvData = Import-Csv -Path "C:\Users\Administrator\Downloads\excel\notes.csv" -Delimiter ","
# Loop through each row in the CSV and create a pipeline
foreach ($pipeline in $csvData) {
# Output each value
Write-Output "pipelineName: $($pipeline.Name)"
Write-Output "pipelineFolderPath: $($pipeline.'Folder Path')"
Write-Output "pipelineDescription: $($pipeline.Description)"
Write-Output "pipelineRepository: $($pipeline.Repository)"
Write-Output "pipelineBranch: $($pipeline.Branch)"
Write-Output "pipelineYamlPath: $($pipeline.'Yaml Path')"
az pipelines create --name $($pipeline.Name) --folder $($pipeline.'Folder Path') --description $($pipeline.Description) --repository $($pipeline.Repository) --branch $($pipeline.Branch) --yml-path $($pipeline.'Yaml Path') --project {projectname}
Write-Output "------------------------"
}
The script output:
The pipelines created:
PS: in my script, you can even remove -Delimiter ","
for csv import, it's also working.