如何通过从单个或多个 csv 文件调用对象来创建多个 azure devops 管道?

问题描述 投票:0回答:1

如何通过从单个或多个 csv 文件调用对象来在 Microsoft Azure DevOps 中创建多个管道?

脚本如何从 Excel 列之一中拾取空白区域?例如文件夹路径

这就是我目前所拥有的。

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

变量的值。

$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

这是我收到的错误消息。

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

这是我的 csv 文件

azure azure-devops azure-cli
1个回答
0
投票

如果您的 CSV 文件存储在变量

$pipelineVariables
中,那么要选择文件夹路径或 Yaml 路径(带空格),您只需:

$pipelineFolderPath = $pipelineVariables."Folder Path"
$pipelineYamlPath = $pipelineVariables."Yaml Path"

示例

这是包含 CSV 文件和数据的简单示例:

  1. 首先,通过将其导入到一个变量中,我可以看到在我的例子中它没有正确地将其创建到 Powershell 对象数组中:

  2. 为了解决这个问题

    -Delimiter ";"
    正在使用:

  3. 带有

    foreach
    循环的示例代码片段:

$Csv = Import-Csv .\CreatePipelineExample.csv -Delimiter ";"

foreach ($Pipeline in $Csv) {

  az pipelines create --name $Pipeline.Name --folder-path $Pipeline."Folder Path" --description $Pipeline.Description --repository $Pipeline.Repository --branch $Pipeline.Branch --yml-path $Pipeline."Yaml Path"
}

我希望这有帮助! 祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.