gpt4 book ai didi

powershell - 将 Gitlab CI Trigger Curl 转换为 Powershell Invoke-RestMethod

转载 作者:行者123 更新时间:2023-12-05 00:55:03 25 4
gpt4 key购买 nike

有谁知道是否可以转换 curl使用 Invoke-RestMethod 将 Gitlab-CI 中的构建触发为等效于 Powershell 的命令?

示例 curl命令:

curl --request POST \
--form token=TOKEN \
--form ref=master \
--form "variables[UPLOAD_TO_S3]=true" \
https://gitlab.example.com/api/v3/projects/9/trigger/builds

这取自 Gitlab 的 documentation页。

我发现了很多关于转换 curl 的帖子。 Powershell 的脚本,但我没有运气让它工作。以下是我引用的一些链接:
  • How to send multipart/form-data with PowerShell Invoke-RestMethod
  • PowerShell equivalent of curl
  • Running curl via powershell - how to construct arguments?

  • 任何帮助,将不胜感激。

    最佳答案

    您可以直接在 URL 中传递 token 和分支参数。至于变量,将它放入 body 变量应该可以解决问题。

    $Body = @{
    "variables[UPLOAD_TO_S3]" = "true"
    }

    Invoke-RestMethod -Method Post -Uri "https://gitlab.example.com/api/v3/projects/9/trigger/builds?token=$Token&ref=$Ref" -Body $Body

    关于powershell - 将 Gitlab CI Trigger Curl 转换为 Powershell Invoke-RestMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39019544/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com