将Gitlab CI触发器卷曲转换为Powershell Invoke-RestMethod

Jay*_*yer 4 powershell curl gitlab

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

示例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
Run Code Online (Sandbox Code Playgroud)

这取自Gitlab的文档页面。

我发现了很多关于将curl脚本转换为Powershell的帖子,但是我并没有运气。这是我引用的一些链接:

任何帮助,将不胜感激。

Fai*_*iry 5

您可以直接在URL中传递令牌和分支参数。至于变量,将其放入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
Run Code Online (Sandbox Code Playgroud)