I know somewhere i'm doing wrong. I'm new to powershell. I'm trying to automate cloning build pipelines for releases using powershell invoke-restmethod. I'm able to get the list of build pipelines but unable to clone. Here is the code
$resp = Invoke-RestMethod -Uri $url -Method GET -UseDefaultCredential -ContentType "application/json" -headers $headers
#Write-Output $resp
foreach($pipe_id in $resp.value.id)
{
Write-Output $pipe_id
$build_url = "https://dev.azure.com/$organization/$project/_apis/build/definitions?definitionId=**$pipe_id**&api-version=5.0-preview.7"
$res = Invoke-RestMethod -Uri $build_url -Method GET -UseDefaultCredential -ContentType "application/json" -headers $headers | ConvertTo-Json
#Write-Output $res
$JSON =
{
"repository": {
"properties": {
"cleanOptions": "1",
"labelSources": "0",
"reportBuildStatus": "true",
"gitLfsSupport": "false",
"skipSyncSource": "false",
"checkoutNestedSubmodules": "false",
"fetchDepth": "0"
},
"id": "repo_id",
"type": "TfsGit",
"name": "common",
"url": "https://dev.azure.com/$organization/$project/_git/common",
"defaultBranch": "refs/heads/Releases/Release_branch",
"clean": "true",
"checkoutSubmodules": false
},
"id": 7,
"name": "common-clone",
"path": "\\Releases",
"type": "build",
"queueStatus": "enabled"
}
$clone_url = "https://dev.azure.com/$organization/$project/_apis/build/definitions?api-version=5.0-preview.7"
$res = Invoke-RestMethod -Uri $build_url -Method POST -Body $JSON -UseDefaultCredential -ContentType "application/json" -headers $headers
Write-Output $res
}
I'm getting the below error
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: definition.Process","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
Thanks!
GET
? – Shayki Abramczyk$res
variable you get, just convert it to json$res = $res.value | ConvertTo-Json
and give it to the body. – Shayki Abramczyk