huserben / TfsExtensions

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

Invalid Json Primitive #20

Closed spowser closed 6 years ago

spowser commented 7 years ago

Running into an issue trying to queue another build definition. Getting the following output when this step is executed:

Preparing task execution handler. Executing the powershell script: d:\a_tasks\TriggerBuild_32abcf98-0df6-4711-b2e4-66a405d3c1a6\1.11.1\triggerbuild.ps1 Using Current Team Project URL Path to Server: https://mycompany.visualstudio.com/Cloud Platform Using Basic Authentication Build shall be triggered for same user that triggered current build: User1 Triggered Build will use the same source version: 8c227c193efa04240a1bdce81bc45c4455b08939 Using same branch as source version: refs/heads/master Build In Queue Condition is not enabled Dependant Build Condition is not enabled Dependant on Failed Build Condition is not enabled Add Enabler Build Core to list of Builds to trigger System.ArgumentException: Invalid JSON primitive: . at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) at System.Management.Automation.CommandProcessorBase.Complete() 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) Queue new Build for definition Enabler Build Core on https://mycompany.visualstudio.com/Cloud Platform/_apis/build/builds?api-version=2.0 { definition: { id: }, sourceBranch: "refs/heads/master", requestedFor: { id: "3525214d-c318-4549-a481-0c838498c1b1"}, sourceVersion: "8c227c193efa04240a1bdce81bc45c4455b08939"} System.ArgumentException: Invalid JSON primitive: . at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) at System.Management.Automation.CommandProcessorBase.Complete() Queued new Build for Definition Enabler Build Core: https://mycompany.visualstudio.com/Cloud Platform/_build/index?buildId=

I assuming there is something I am doing wrong but not sure where to start looking based on the error output.

huserben commented 7 years ago

Hi @spowser this issue usually happens when something with the authentication is not correct, as it fails to authenticate and thus returns some html data instead of the expected json.

I see that you use Basic Authentication, did you enable this on your TFS? By default it is not enabled and thus the task will fail. In TFS this is called Alternate Credentials - here a link that describes how to enable it: https://binary-stuff.com/post/how-to-enable-alternate-credentials-in-visual-studio-online-vso

However Microsoft recommends to use Personal Access Tokens over the Alternate Credentials, this might be as well worth a thought.

Let me know if I can assist you more in any way.

ajdevops commented 7 years ago

facing similar issue , trying to trigger a build def and getting below error, Note - Use Auth token on private agents to connect to VSTS. so used basic auth and tried other options as well .. no luck, getting below error

Add Little_Test to list of Builds to trigger 2017-08-08T00:16:16.6302548Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-08-08T00:16:16.6312549Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-08-08T00:16:16.6312549Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-08-08T00:16:16.6312549Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-08-08T00:16:16.6312549Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-08-08T00:16:16.6312549Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-08-08T00:16:16.6312549Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input) 2017-08-08T00:16:16.6312549Z at System.Management.Automation.CommandProcessorBase.Complete() 2017-08-08T00:16:16.6322550Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array. 2017-08-08T00:16:16.6322550Z at CallSite.Target(Closure , CallSite , Object , Int32 ) 2017-08-08T00:16:16.6322550Z at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) 2017-08-08T00:16:16.6322550Z at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) 2017-08-08T00:16:16.6322550Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) 2017-08-08T00:16:16.6352553Z Queue new Build for definition Def2 on https://comp1.visualstudio.com/AEXX/_apis/build/builds?api-version=2.0 2017-08-08T00:16:16.6352553Z { definition: { id: }, sourceBranch: "$/AEPP", requestedFor: { id: "xxx-da8e-6xx8-85f1-xxxxxxx"}}

ajdevops commented 7 years ago

seems like its passing null for the target build id, last line in the log.

huserben commented 7 years ago

Hi

yes it looks like for both that the id is not set, and that usually is a sign that something with the authentication did fail when trying to fetch the id for the build. Do you happen to have any special characters or something in your build definitions you want to trigger?

huserben commented 7 years ago

I just uploaded a completly refactored Task - it's now in version 2.0.0. Can you please update to this version as described here: https://marketplace.visualstudio.com/items?itemName=benjhuser.tfs-extensions-build-tasks

Can you please update and try again, even if the problem still persists we might get more info on the actual problem as the logging should be improved :-)

spowser commented 7 years ago

I have updated to version 2 and switched the authentication to Personal Token. Everything seems to be working with the token.

Before switching the authentication to Personal Token, I tried using it with Basic Authentication and I received this error

2017-08-15T13:38:44.1939570Z ##[error]Cannot read property '0' of undefined

huserben commented 7 years ago

Hi @spowser ok super, so there was probably some issue with the Basic Auth - however if it works with the PAT then i guess that's fine.

What about you @ajdevops ? Can you try to update the Task as well to version 2 and let me know if something changed?

huserben commented 7 years ago

Hi @ajdevops

can you please give me some update if your issue still persists? And if so please help me out with some logs or additional info?

huserben commented 6 years ago

I will close this issue now as no further information provided. Anyhow with the newest version the logging was improved, in case of a failed authentication the task will immediately fail and add a proper output message. Hope that will prevent further confusion why its not working.