huserben / TfsExtensions

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

Getting following exception System.ArgumentException: Invalid JSON primitive #18

Closed LesCodeables closed 7 years ago

LesCodeables commented 7 years ago

I created a main build definition through which I'm trying to trigger another build definition using Trigger Build step. I get the following error in powershell script:

2017-07-18T08:44:56.3238027Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-07-18T08:44:56.3238027Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-07-18T08:44:56.3238027Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-07-18T08:44:56.3238027Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-07-18T08:44:56.3238027Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-07-18T08:44:56.3238027Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-07-18T08:44:56.3238027Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ProcessRecord() 2017-07-18T08:44:56.3238027Z at System.Management.Automation.CommandProcessor.ProcessRecord() 2017-07-18T08:44:56.3398228Z ##[error]System.Management.Automation.RuntimeException: Cannot index into a null array. 2017-07-18T08:44:56.3398228Z at CallSite.Target(Closure , CallSite , Object , Int32 ) 2017-07-18T08:44:56.3398228Z at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) 2017-07-18T08:44:56.3398228Z at System.Management.Automation.Interpreter.DynamicInstruction3.Run(InterpretedFrame frame) 2017-07-18T08:44:56.3398228Z at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) 2017-07-18T08:44:56.3398228Z Queue new Build for definition Product2010_MSIbuild on https://abc.visualstudio.com/Company Product/_apis/build/builds?api-version=2.0 2017-07-18T08:44:56.3398228Z { definition: { id: }, sourceBranch: "$/Company Product/Dev/Product", requestedFor: { id: "5a7e04d2-0172-4243-afd9-d1bdf12169b5"}} 2017-07-18T08:44:56.4758236Z ##[error]System.ArgumentException: Invalid JSON primitive: . 2017-07-18T08:44:56.4758236Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() 2017-07-18T08:44:56.4758236Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) 2017-07-18T08:44:56.4758236Z at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) 2017-07-18T08:44:56.4758236Z at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) 2017-07-18T08:44:56.4758236Z at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error) 2017-07-18T08:44:56.4758236Z at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ProcessRecord() 2017-07-18T08:44:56.4758236Z at System.Management.Automation.CommandProcessor.ProcessRecord() 2017-07-18T08:44:56.4758236Z Queued new Build for Definition Product2010_MSIbuild: https://abc.visualstudio.com/Company Product/_build/index?buildId= 2017-07-18T08:44:56.4758236Z ##[error]PowerShell script completed with 3 errors.`

huserben commented 7 years ago

Hi

looking at your logs it seems to have a problem to fetch the ID for the build definition you want to trigger. This could have several reasons, for example that there is a typo where you specified the build that shall be triggered. Another problem could be that the authentication is not successful. What kind of authentication are you using?

LesCodeables commented 7 years ago

Hi, You were right, the issue was with the authentication. I tried basic authentication using my username and password, which did not work. Then I tried Personal Token and it worked fine. Thanks!