To do the same using cURL and a more recent API version (6.0, but seems to work at least up to API version 7.1-preview.7):
YOUR_PAT_TOKEN_ENCODED_IN_BASE64=... // https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows#create-a-pat
AZURE_ORGANIZATION=...
AZURE_PROJECT=...
PIPELINE_ID=...
FULL_GIT_SHA=...
curl --location \
--request POST 'https://dev.azure.com/$AZURE_ORGANIZATION/$AZURE_PROJECT/_apis/build/builds?api-version=6.0' \
--header 'Authorization: Basic $YOUR_PAT_TOKEN_ENCODED_IN_BASE64' \
--header 'Content-Type: application/json' \
--data-raw '{
"definition": {
"id": "$PIPELINE_ID"
},
"sourceVersion" : "$FULL_GIT_SHA"
}'
Don't know what your PIPELINE_ID is?
Go to the Azure Pipeline website, click on your pipeline and look at the URL: https://dev.azure.com/yourorganization/yourproject/_build?definitionId=42 -> the definitionId
is the one you want.
(Note: there is also a sourceBranch
parameter but I did not manage to get it working, Azure keeps ignoring it and using the default branch...)