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

时间:2016-08-18 13:30:32

标签: powershell curl gitlab

是否有人知道是否可以使用curl将用于触发Gitlab-CI构建的Invoke-RestMethod命令转换为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页面中获取的。

我发现了很多关于为Powershell转换curl脚本的帖子,但是我没有运气让它运转起来。以下是我引用的一些链接:

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:4)

您可以直接在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

答案 1 :(得分:1)

或者,您可以在body参数中传递所有参数:

$form = @{token = $CI_JOB_TOKEN;ref = $BRANCH_TO_BUILD; "variables[SERVER_IMAGE_TAG]" = $CI_COMMIT_REF_NAME}
Invoke-WebRequest -Method POST -Body $form -Uri https://gitlab.example.com/api/v4/projects/602/trigger/pipeline -UseBasicParsing
相关问题