huserben / TfsExtensions

Extensions for TFS 2015+ such as custom Widgets (require TFS 2017) and Build Tasks
MIT License
45 stars 22 forks source link

The latest version throw 409 conflict error #7

Closed nobitagamer closed 7 years ago

nobitagamer commented 7 years ago

2017-05-15T04:25:22.8872856Z { definition: { id: 3 }, sourceBranch: "refs/heads/develop", requestedFor: { id: "380f3874-7393-494b-b2be-944f24d80053"}} 2017-05-15T04:25:23.5687684Z ##[error]System.Net.WebException: The remote server returned an error: (409) Conflict. 2017-05-15T04:25:23.5687684Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) 2017-05-15T04:25:23.5687684Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() 2017-05-15T04:25:23.8041351Z ##[error]System.Net.WebException: The remote server returned an error: (400) Bad Request. 2017-05-15T04:25:23.8041351Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) 2017-05-15T04:25:23.8041351Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() 2017-05-15T04:25:23.8046167Z Queued new Build for Definition *****

nobitagamer commented 7 years ago

After uncheck Queue Build for user that triggered original build the following 400 error is thrown:

2017-05-15T04:31:47.9346717Z { definition: { id: 3 }, sourceBranch: "refs/heads/develop", sourceVersion: "C156b98e7859098c40f1f5de79e649b2672f5f38b"} 2017-05-15T04:31:48.4638259Z ##[error]System.Net.WebException: The remote server returned an error: (400) Bad Request. 2017-05-15T04:31:48.4638259Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) 2017-05-15T04:31:48.4638259Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() 2017-05-15T04:31:48.6926161Z ##[error]System.Net.WebException: The remote server returned an error: (400) Bad Request. 2017-05-15T04:31:48.6926161Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) 2017-05-15T04:31:48.6926161Z at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() 2017-05-15T04:31:48.6930986Z Queued new Build for ****

huserben commented 7 years ago

so it does not work with any setup for you right now? :-( or just with a/some specific configurations?

nobitagamer commented 7 years ago

It does not work at all, now my builds cannot trigger.

nobitagamer commented 7 years ago

I found that problem is 'sourceVersion' must be in 'parameters' and the 'requestedFor' property cause error too! Uncheck both Queue Build for user that triggered original build and Use current changeset for the triggered build the build will work again.

{ definition: { id: 3 }, sourceBranch: "refs/heads/develop", parameters: { sourceVersion: "C156b98e7859098c40f1f5de79e649b2672f5f38b"} } will work.

Maybe both sourceVersion and requestedFor must be wrapped inside parameters.

By the way it better if you can output the response this will easy to find out the problem:

Instead of use Invoke-WebRequest you can use Invoke-RestMethod this work for me with output response, here is my sample code:

$result = Invoke-RestMethod -Uri $url -Method Post -Body (ConvertTo-Json $body) -ContentType "application/json" -Headers @{ Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($apiKey)")) } Write-Host "Result = $($result | ConvertTo-Json -Depth 100)"

huserben commented 7 years ago

Hi

hmm that is strange, i tested this things and found no issues. I will try to move it to the parameters and see. Could it be that it is different for TFS and Git Repos?...

I will as well check the Output, but once this was actually giving me an exception in the script to write the response...

I hope your build now works again with the mentioned settings, as I don't have time to fix something today...

nobitagamer commented 7 years ago

I think the problem is different between on-premise TFS and VSTS as API specified here: https://www.visualstudio.com/en-us/docs/integrate/api/build/builds

It's ok for me now, make your time and fix it later! Thanks so much.

huserben commented 7 years ago

Hi

where exactly did you find the difference between on-prem and vsts on the site? So you are using on-prem TFS then?

Sorry again for the inconvenience

nobitagamer commented 7 years ago

No i'm using VSTS and don't know if there is any different, i just think about it because don't see the field you are using in MS document.

huserben commented 7 years ago

ok, then I think i will try to reproduce the issue on a git repo.

huserben commented 7 years ago

I could reproduce the error on a git repo and managed to fix it. But for the "requestedFor" I did not have any issues, it only was a problem for the source version. You had issues as well if you just had the "requestedFor" active without source version?

I updated the Task now with the fix for the sourceVersion. Please let me know if you still have issues with the requestedFor.

Thanks for your support

nobitagamer commented 7 years ago

The "requestedFor" worked with the latest version, thank you so much and i close this issue now.