您可以先使用Pipelines - Getrest api查看管道的定义json,并相应更改字段。
在调用Pipelines - Createrest api时,可以如下定义请求体json:
$body = @{
configuration=@{
variables=@{
customVariable=@{
value="value"
}
};
path="azure-pipelines.yml";
repository=@{
id= "repository-id";
name="repository-name"
type= "azureReposGit"
};
type= "yaml"
};
name= "pipeline-name";
folder= "\\"
}
variables 字段定义 UI 页面中的管道变量:
path 字段指向代码仓库中的管道 yaml 文件。
repository 字段定义了此管道目标的代码仓库。
folder 字段定义了管道所在的文件夹:
如果你使用Build Definitions - Createrest api 创建yaml 管道。您可以查看以下请求正文 json 示例:
$body='{ "variables": {
"customVariable": {
"value": "customValue",
"allowOverride": true
}
},
"process": {
"yamlFilename": "azure-pipelines.yml",
"type": 2
},
"repository": {
"id": "repo-id",
"type": "TfsGit",
"name": "repo-Nanme",
"defaultBranch": "refs/heads/master",
"clean": null,
"checkoutSubmodules": false
},
"name": "pipeline-name",
"path": "\\",
"type": "build",
"queueStatus": "enabled",
"project": {
"id": "project-id",
"name": "project-name"
}
}'
更新:
如果你的代码库是 Githbub。您必须在您的 azure devops 项目中创建一个github service connection。然后在您的 api resquest body 中传递连接 id。
$body = @{
configuration=@{
variables=@{
customVariable=@{
value="value"
}
};
path="azure-pipelines.yml";
repository=@{
FullName="githubAccount/repoName";
type= "gitHub";
Connection= @{
id= "github service connection id"
}
};
type= "yaml"
};
name= "pipeline-name";
folder= "\\"
}
您可以在地址栏中获取服务连接ID。见下文: