简体   繁体   English

用户 PowerShell 在 Azure Devops 中排队构建

[英]User PowerShell to Queue a Build in Azure Devops

There are a few related questions in stack I'll drop them below.堆栈中有一些相关的问题,我将它们放在下面。 I'm working with Azure DevOps api 5.1 and attempting to queue a build.我正在使用 Azure DevOps api 5.1 并尝试将构建排队。

{
    "Definition": {
        "id": "7"
    }
}

This will queue a build with the variables that are already set in the definition.这将使用已在定义中设置的变量对构建进行排队。 I have attempted to pass in variables in a few different ways both of which wound up not being honored by the API at all.我试图以几种不同的方式传递变量,这两种方式都没有得到 API 的认可。

{
    "Definition": {
        "id": "7",
        "variables": {
            "tag": "@{value=v1.1.0}",
            "system.debug": "@{value=true}"
        }
    }
}

Per some of the related questions I also attempted根据我也尝试过的一些相关问题

{
    "Definition": {
        "id": "7",
        "parameters": {
            "tag": "@{value=v1.1.0}",
            "system.debug": "@{value=true}"
        }
    }
}

After capturing the output from chrome while queuing a build via the UI it appears to expect variables as opposed to parameters, but what i'm seeing when i go back to view the builds is that the variables being passed in are not being honored.在通过 UI 对构建进行排队时从 chrome 捕获 output 后,它似乎期望变量而不是参数,但是当我 go 返回查看构建时,我看到的是传入的变量没有得到尊重。 Additionally I have taken the definition I wish to run and stashed it into the body.definition above.此外,我已经采用了我希望运行的定义并将其隐藏到上面的 body.definition 中。

VSTS use API to set build parameters at queue time VSTS 使用 API 在队列时设置构建参数

TFS 2017 API; TFS 2017 API; Queuing a build with variables 使用变量排队构建

How to QUEUE a new build using VSTS REST API 如何使用 VSTS REST API 对新构建进行排队

Please let me know if I should add more detail I've not put the actual code, but it is pretty straightforward请让我知道我是否应该添加更多细节我没有放实际代码,但这很简单

Invoke-RestMethod -Method post -Uri $uri -Headers $Header -ContentType 'application/json' -Body ($Body |ConvertTo-Json -Compress -Depth 10)

After firing up postman and finding a collection it appears there were two issues with how I was attempting to pass the variables.在启动 postman 并找到一个集合后,我尝试传递变量的方式似乎存在两个问题。

Problem 1: variables vs parameters问题 1:变量与参数

Even though based on several questions here as well as capturing the traffic from web browser to devops.即使基于这里的几个问题以及从 web 浏览器到 devops 的流量。 You cannot use variables as a part of the definition, it must be parameters.您不能将变量用作定义的一部分,它必须是参数。 Additionally it appears that they cannot be nested inside the definition (body.definition.parameters) they must be at the same level as defintions (body.parameters).此外,它们似乎不能嵌套在定义(body.definition.parameters)中,它们必须与定义(body.parameters)处于同一级别。

Problem 2: format问题2:格式

The parameters value must be compressed json, additionally it cannot be an object, it must be variable:value.参数值必须是压缩的json,另外不能是object,必须是variable:value。

{
    "definition": {
        "id": 7
    },
    "parameters": "{\"tag\":\"v3.2.1\"},\"system.debug\":\"true\"}"
}

I feel I've seen this answer before possibly in one of the related questions I posted above.我觉得我之前可能在我上面发布的相关问题之一中看到过这个答案。 Apologies for all the duplication of effort.为所有重复的努力道歉。

There is also the Run Pipeline rest api available:还有可用的运行管道 rest api:

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1 POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1

pipelineId in url is definitionId url 中的 pipelineId 是定义 ID

{
  "templateParameters": {
    "param1": "paramValue1",
    "param2": "paramValue2",
    "param3": "paramValue3"
  }
}

Documented here .记录在这里

Not enough rep to comment没有足够的代表发表评论

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

相关问题 Powershell触发Azure DevOps中的构建 - Powershell to trigger a build in Azure DevOps 使用Powershell脚本在Azure DevOps上进行角度生成错误 - Angular build error on Azure DevOps with powershell script 如何通过 Powershell 在 Azure Devops 中生成构建工件 - How to generate a build artifact in Azure Devops through Powershell 在PowerShell中使用Azure DevOps REST API更新内部版本定义 - Update build definition using Azure DevOps REST API in PowerShell Azure Devops yaml 构建定义 PowerShell 内联语法问题 - Azure Devops yaml build definition PowerShell inline Syntax problem 在本地使用 PowerShell 在分支上获取 Azure DevOps last build id - Use PowerShell locally to get Azure DevOps last build id on branch Azure Devops Powershell 任务:生成变量的编程访问 - Azure Devops Powershell task: Programmatic Access of Build Variables Azure DevOps - 从 powershell 存储构建/发布变量 - Azure DevOps - Store build/release variables from powershell Powershell 从 azure devops build pipeline 获取组件治理结果 - Powershell to fetch the Component Governance result from azure devops build pipeline 将管道变量作为参数传递到 Powershell 构建步骤在 Azure DevOps 中不起作用 - passing pipeline variable as argument into Powershell build step not working in Azure DevOps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM