huserben / TfsExtensions

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

Cannot read property 'length' of null #99

Closed SimoneLocatelli closed 5 years ago

SimoneLocatelli commented 5 years ago

Hi,

I've created a build definition containing a single Trigger Build task and configured it with the following settings: https://image.ibb.co/ciT9uK/settings.png

However, the task fails during its execution with the message: Cannot read property 'length' of null

Here's the full task log

2018-10-03T10:17:32.9276554Z ##[section]Starting: UAT Build 2018-10-03T10:17:32.9479263Z Task : Trigger Build 2018-10-03T10:17:32.9479514Z Description : This tasks allows to trigger a new Build (add it to the queue) as part of a Build Definition. It contains as well some conditions that can be applied, for example if the last build of certain definition was successful or not. 2018-10-03T10:17:32.9479668Z Version : 3.0.3 2018-10-03T10:17:32.9479785Z Author : Benjamin Huser 2018-10-03T10:17:32.9479878Z Help : 2018-10-03T10:17:33.5428932Z Using current Team Project 2018-10-03T10:17:33.5429119Z Team Project: ********* with ID *************************** 2018-10-03T10:17:33.5429254Z Using current Collection Url 2018-10-03T10:17:33.5429356Z Server URL: https://**********.visualstudio.com/ 2018-10-03T10:17:33.5429576Z Using Personal Access Token 2018-10-03T10:17:33.5475471Z ##[error]Cannot read property 'length' of null 2018-10-03T10:17:33.5501056Z ##[section]Finishing: UAT Build

Any idea what's going on?

huserben commented 5 years ago

Hi @SimoneLocatelli

thanks for reporting this issue.

My first guess would be that there is no actual Person Access Token defined? I cannot see the "Authentication" section of your configuration in the picture you shared.

So if you're using a PAT you have to specifiy the token in the "Password" section. Ideally you do this via a variable which you set to be secret, so you don't have the token hanging around in clear text. If you dont want to specify the token you can as well use OAuth, then the password field can be empty. However you have to configure the build definition to allow the access to the OAuth token as described here: https://github.com/huserben/TfsExtensions/blob/master/BuildTasks/overview.md#oauth-token

Please let me know if this fixed the problem, otherwise I'll need to have a closer look into the code and maybe need some log files of a build with the "system.debug" variable set to true to get more log output.

SimoneLocatelli commented 5 years ago

Hi @huserben

thank you very much for your reply. I think you're since I haven't set up the PAT. I've thought it would have been necessary only to access a build definition located on a different project/server. I will try that tomorrow.

On a side note, it would be great if you could add some checks before trying to use the PAT so that a better error message is returned. Anyway, thanks again for your help and for developing this great extension.

Cheers

Simone

huserben commented 5 years ago

Ok, please let me know once you tried whether it was fixed or not.

In any case I will let this issue stay open until I have improved the logging output for the different use cases of Authentication. Thanks for that input.

SimoneLocatelli commented 5 years ago

Hi @huserben

Once I've added the PAT, the task started working as expected. Thanks a lot for your help!

huserben commented 5 years ago

Hi

ok very good.

Thanks for reporting your issue and proposing the improvements in the logs in case of such an error. Until I'll updated the task accordingly I will leave the issue open.

Please don't hesitate to open another issue in case you have any problem or a feature request.

huserben commented 5 years ago

The newest version of the tasks has a built in check whether the authentication options are containing all necessary info, if not there will be a more meaningful message: grafik