Azure devops 我们如何使用Azure Devops rest api创建Azure管道(yaml方法)
我们如何使用Azure Devops rest API创建Azure管道(yaml方法)。 基本上,我尝试通过编程方式创建一个新管道,而不是通过Azure Devops门户 我在下面提到了这个链接: 但这并没有提供创建和配置指向代码repo的新管道所需的确切json正文格式。请在此帮助我您可以首先使用RESTAPI检查管道的json定义,并相应地更改字段 在调用Azure devops 我们如何使用Azure Devops rest api创建Azure管道(yaml方法),azure-devops,azure-devops-rest-api,Azure Devops,Azure Devops Rest Api,我们如何使用Azure Devops rest API创建Azure管道(yaml方法)。 基本上,我尝试通过编程方式创建一个新管道,而不是通过Azure Devops门户 我在下面提到了这个链接: 但这并没有提供创建和配置指向代码repo的新管道所需的确切json正文格式。请在此帮助我您可以首先使用RESTAPI检查管道的json定义,并相应地更改字段 在调用Pipelines-Createrestapi时,可以如下定义请求主体json: $body = @{ configuration=
Pipelines-Create
restapi时,可以如下定义请求主体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= "\\"
}
变量
字段定义UI页面中的管道变量:
path
字段指向代码repo中的管道yaml文件
repository
字段定义此管道目标的代码回购
文件夹
字段定义放置管道的文件夹:
如果使用RESTAPI创建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项目中创建一个。然后在api请求正文中传递连接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。见下文:
使用web界面创建管道,并使用GET-from API查看JSON格式:非常感谢@Levi的快速响应。我最初收到以下错误:“消息”:“值不能为null。\r\n参数名称:Url”。但后来我在repository下传递了URL的值,它创建了一个新的管道。但是现在我无法从Azure Devops UI编辑或打开设置,它显示以下错误:“值不能为null。参数名称:serviceEndpointId”以及如何在以编程方式创建管道后立即执行管道github上的代码存储库是什么?管道中是否使用了任何服务连接?是的,我的代码repo是GitHub。是的,如果您的代码repo是GitHub,我在管道@levif中使用了服务连接名称。您必须在azure devops项目中创建一个。然后在api请求正文中传递连接id。见以上更新。