简体   繁体   English

如何使用 Azure DevOps REST API 对构建进行排队

[英]How to Queue a Build Using Azure DevOps REST API in Python?

I want to be able to queue an Azure DevOps build using python.我希望能够使用 python 对 Azure DevOps 构建进行排队。

I have the following code:我有以下代码:

params_dict = {
        "id" : [Build ID #]
    }

url = "https://dev.azure.com/[my_organization]/[my_project]/_apis/build/builds?api-version=5.1"

requests.post(url, json = params_dict, auth=(username, password))

However, when I run this code, I get:但是,当我运行此代码时,我得到:

{'$id': '1',
 'errorCode': 0,
 'eventId': 0,
 'innerException': None,
 'message': 'Value cannot be null.\r\nParameter name: build.Definition',
 'typeKey': 'ArgumentNullException',
 'typeName': 'System.ArgumentNullException, mscorlib'}

I've tried using build.Definition in the params_dict, definition , etc. No permutation seems to work.我尝试在 params_dict、 definition等中使用build.Definition 。似乎没有任何排列起作用。 I get the same error for them all.我对他们所有人都犯了同样的错误。

What key do I need to give in my params_dict to make this work?我需要在 params_dict 中提供什么键才能完成这项工作?

After much trial and error, I figured out the correct format for the params_dict is:经过反复试验,我发现 params_dict 的正确格式是:

params_dict = {
    "definition": {
        "id": [Build ID #]
    } 
}

Using this dictionary, the build successfully queues.使用此字典,构建成功排队。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM