Jay Soyer Jay Soyer - 3 months ago 61
PowerShell Question

Convert Gitlab CI Trigger Curl to Powershell Invoke-RestMethod

Does anyone know if it's possible to convert the

curl
command used to trigger builds in Gitlab-CI to a Powershell equivalent using
Invoke-RestMethod
?

Example
curl
command:

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


This was taken from Gitlab's documentation page.

I found quite a few postings about converting a
curl
script for Powershell but I haven't had any luck in getting it to work. Here are some of the links I referenced:



Any help would be appreciated.

Answer

You can pass the token and the branch parameters directly in the URL. As for variables, putting it into the body variable should do the trick.

$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