Closed lukx closed 7 years ago
Just so you don't have too scroll through the HTML Page, the error hidden in there is
Microsoft Internet Explorer's Enhanced Security Configuration is currently enabled on your environment. This enhanced level of security prevents our web integration experiences from displaying or performing correctly. To continue with your operation please disable this configuration or contact your administrator.
I am opening a Build-Agent Ticket at VSTS [Edit] Done at https://github.com/Microsoft/vsts-agent/issues/885
Hi
do you specify the username and password for for the user that accesses the TFS API under Advanced Configuration? If you use a hosted build agent you need to specify a username/password combination that has the required rights on the TFS.
I tried quickly with a git Repo hosted on VSTS and it worked when specifiying username/password, by default this option is not enabled and i had the similar issue:
2017-03-29T18:40:49.9708860Z Preparing task execution handler. 2017-03-29T18:40:54.6575987Z Executing the powershell script: C:\a\_tasks\TriggerBuild_32abcf98-0df6-4711-b2e4-66a405d3c1a6\1.3.16\triggerbuild.ps1 2017-03-29T18:40:55.2524957Z Using Current Team Project URL 2017-03-29T18:40:55.2915096Z Path to Server: https://benjsawesometfstest.visualstudio.com//GitTest 2017-03-29T18:40:55.2915096Z Using Default Credentials 2017-03-29T18:40:55.2915096Z Build In Queue Condition is not enabled 2017-03-29T18:40:55.2924909Z Dependant Build Condition is not enabled 2017-03-29T18:40:55.5950195Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-03-29T18:40:55.5950195Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-03-29T18:40:55.5950195Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-03-29T18:40:55.5950195Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-03-29T18:40:55.5950195Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-03-29T18:40:55.5950195Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-03-29T18:40:55.5950195Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) 2017-03-29T18:40:55.5950195Z at System.Management.Automation.CommandProcessorBase.Complete()
Even set the username and password, i'm still have the above error.
You are sure the user has the rights to access the TFS API? Could you try to manually send the request with the credentials and check the return value? I think as well that you would need to allow "alternate authentication credentials" via your Profile --> Security -> Alternate Authentication Credentials and then use this username/password combination to trigger the build.
Otherwise could you setup a demo VSTS project that I could access and in which the error is reproduced?
Hi @lukx and @nobitagamer do you have any updates? I'd like to help but it's hard as I cannot really reproduce the issue, except if there is a problem with the Authentication which causes the TFS API to reroute to a login page, and in that case it is more a setting issue than a problem with the scripts.
I would really appreciate the return value of the webrequest. With Postman you can send a request to this url: https://**yourtfs**.visualstudio.com/DefaultCollection/**yourproject/team**/_apis/build/builds?api-version=2.0 If you are not using VSTS just adapt accordingly and set the correct collection.
Thanks for your collaboration
Yes, with Postman i can send request successfully, now workaround for me is use a Powershell step to invoke web request to that API but that's not my expected solution since your extension provide really cool feature that i need.
Below is my script in case you need: ` $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds?api-version=2.0" $body = "{ 'definition' : { 'id' : $env:IOSBUILD_DEFINITIONID }, 'sourceBranch' : '$env:BUILD_SOURCEBRANCH' }" $type = "application/json"
$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
Write-Host "URL: $url" $definition = Invoke-RestMethod -Uri $url -Body $body -ContentType $type -Method Post -Headers $headers Write-Host "Definition = $($definition | ConvertTo-Json -Depth 100)" `
P/S: I've dig into your source and i think may be problem because you're using Basic Authentication instead of Bearer header like me (VSTS maybe updated and force that or whatever i'm not sure).
Hi
oh ok, now it makes sense. I think I never tested that so far, sorry. I will have a look as soon as possible.
Hi the lates check in should have solved your issue. Version 1.4.0 should now support the usages of Personal Access Tokens. I updated the version in the Marketplace, next time you run the build it should automatically take this one.
Please test it and let me know if it worked :-)
Really appreciated your help in solving this issue, thank you 👍
With 'Default' checked:
2017-04-04T02:34:07.0910307Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-04-04T02:34:07.0910307Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-04-04T02:34:07.0910307Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-04-04T02:34:07.0910307Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-04-04T02:34:07.0910307Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-04-04T02:34:07.0910307Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-04-04T02:34:07.0910307Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) 2017-04-04T02:34:07.0910307Z at System.Management.Automation.CommandProcessorBase.Complete() 2017-04-04T02:34:07.0920327Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array. 2017-04-04T02:34:07.0920327Z at CallSite.Target(Closure , CallSite , Object , Int32 ) 2017-04-04T02:34:07.0920327Z at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) 2017-04-04T02:34:07.0920327Z at System.Management.Automation.Interpreter.DynamicInstruction
3.Run(InterpretedFrame frame)
2017-04-04T02:34:07.0920327Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2017-04-04T02:34:07.6168472Z ##[error]System.ArgumentException: Invalid JSON primitive: .
2017-04-04T02:34:07.6168472Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
2017-04-04T02:34:07.6168472Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
2017-04-04T02:34:07.6168472Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
2017-04-04T02:34:07.6168472Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
2017-04-04T02:34:07.6168472Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error)
2017-04-04T02:34:07.6168472Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input)
2017-04-04T02:34:07.6168472Z at System.Management.Automation.CommandProcessorBase.Complete()
2017-04-04T02:34:07.6188738Z Checking Build Definition:
2017-04-04T02:34:08.1410598Z ##[error]System.ArgumentException: Invalid JSON primitive: .
2017-04-04T02:34:08.1410598Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
2017-04-04T02:34:08.1410598Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
2017-04-04T02:34:08.1410598Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
2017-04-04T02:34:08.1410598Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
2017-04-04T02:34:08.1410598Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error)
2017-04-04T02:34:08.1410598Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input)
2017-04-04T02:34:08.1410598Z at System.Management.Automation.CommandProcessorBase.Complete()
2017-04-04T02:34:08.1410598Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array.
2017-04-04T02:34:08.1410598Z at CallSite.Target(Closure , CallSite , Object , Int32 )
2017-04-04T02:34:08.1410598Z at System.Management.Automation.Interpreter.DynamicInstruction3.Run(InterpretedFrame frame) 2017-04-04T02:34:08.1410598Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) 2017-04-04T02:34:08.6607702Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-04-04T02:34:08.6607702Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-04-04T02:34:08.6607702Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-04-04T02:34:08.6607702Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-04-04T02:34:08.6607702Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-04-04T02:34:08.6607702Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-04-04T02:34:08.6607702Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) 2017-04-04T02:34:08.6607702Z at System.Management.Automation.CommandProcessorBase.Complete() 2017-04-04T02:34:08.6607702Z None of the blocking builds is queued - proceeding 2017-04-04T02:34:09.1822849Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-04-04T02:34:09.1822849Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-04-04T02:34:09.1822849Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-04-04T02:34:09.1822849Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-04-04T02:34:09.1822849Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-04-04T02:34:09.1822849Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-04-04T02:34:09.1822849Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) 2017-04-04T02:34:09.1822849Z at System.Management.Automation.CommandProcessorBase.Complete() 2017-04-04T02:34:09.1822849Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array. 2017-04-04T02:34:09.1822849Z at CallSite.Target(Closure , CallSite , Object , Int32 ) 2017-04-04T02:34:09.1822849Z at System.Management.Automation.Interpreter.DynamicInstruction
3.Run(InterpretedFrame frame)
2017-04-04T02:34:09.1822849Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)`
With 'Default' unchecked and PAT selected:
Checking if blocking builds are queued
Checking Build Definition: pudge-war vNext-CI
Checking Build Definition:
System.Net.WebException: The remote server returned an error: (400) Bad Request. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() System.Management.Automation.RuntimeException: Cannot index into a null array. at CallSite.Target(Closure , CallSite , Object , Int32 ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at System.Management.Automation.Interpreter.DynamicInstruction
3.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
None of the blocking builds is queued - proceeding`
PS: I think the above error because i'm leave the textbox empty like below:
After fill in some text the task worked correctly but not as my expected: Check the use 'Default', turn on 'Allow Scripts to Access OAuth Token' and Done!
The correct fix maybe:
include
$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
in Invoke-WebRequest instead of:
-UseDefaultCredentials
in your code (the $env:SYSTEM_ACCESSTOKEN can be access only when turn on 'Allow Scripts to Access OAuth Token')
Hi sorry again, when I looked at it yesterday, I thought you would need to use Personal Access Tokens and not OAuth, my bad. I will try to have a look at it tonigt (CET) and will let you know when I'm done. Do you know if there is the need to ever specifiy the token yourself instead of using "System.AccessToken"? From what I saw it is not available in the Release Management as a variable. If so I would make it as well configurable and leave the option to either use default credentials, default access token, or using Personal Access Token, OAuth Token or Basic Auth.
Thanks again for your support
The 'System.AccessToken' is generic access token that's enough for read-only tasks and queue build action so i'll never generate a PAT for some tasks except in case i need to push code back too my repository that requires a write permission. With your current Default checkbox, use System.AccessToken maybe the best solution.
Aw, now i'm facing with error:
None of the blocking builds is queued - proceeding Queue new Build for definition pudge-war vNext-CI System.Net.WebException: The remote server returned an error: (409) Conflict. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() System.Net.WebException: The remote server returned an error: (400) Bad Request. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() Queued new Build for Definition pudge-war vNext-CI (Unity3D on macOS) PowerShell script completed with 2 errors.
But it still success until tonight.
Hi I just uploaded a new version that supports the OAuth Access Token. Please try it and come back to me
Cool, now it worked like a charm. That's perfect, thank you!
Ok, i'll close the issue then.
Thanks for your support, helped me a lot in figuring out what was actually wrong 👍
Opening this ticket to keep track of the Problem I mentioned in #1
When using the TriggerBuild Build Step on a VSTS environment and a hosted build agent, we are getting the following error (after working around the issue #1):
As suggested, we traced back the exact request by adding an
Inline PowerShell
step requesting the API as it would do with the provided script. The result is the followingWe'll invest some more time into looking into the reasons this page is displayed to our API client.