MicrosoftPremier / VstsExtensions

Documentation and issue tracking for Microsoft Premier Services Visual Studio Team Services Extensions
MIT License
57 stars 14 forks source link

Cannot read property 'id' of null when running 'Clean Agent Directories' task #3

Closed camp-007 closed 6 years ago

camp-007 commented 6 years ago

I'm trying to use the 'Clean Agent Directories' extension and it doesn't seem to be working. We use VSTS, and an on-prem build agent. Here is the log file which looks like it is encountering an error, but I don't have much else to go on.

Anything else I should look into to diagnose why it isn't running properly?

2018-05-15T19:41:24.0661381Z ##[section]Starting: Clean Agent Directories
2018-05-15T19:41:24.0661381Z ==============================================================================
2018-05-15T19:41:24.0661381Z Task         : Post Build Cleanup
2018-05-15T19:41:24.0661381Z Description  : Cleans the build directories on the agent after the build has finished.
2018-05-15T19:41:24.0661381Z Version      : 3.0.1
2018-05-15T19:41:24.0661381Z Author       : Microsoft Premier Services
2018-05-15T19:41:24.0661381Z Help         : [More information](https://github.com/almtcger/VstsExtensions/blob/master/PostBuildCleanup/en-US/overview.md)
2018-05-15T19:41:24.0661381Z ==============================================================================
2018-05-15T19:41:25.4880283Z SystemVssConnection exists true
2018-05-15T19:41:26.0661626Z Cannot read property 'id' of null
2018-05-15T19:41:26.0661626Z ##[section]Finishing: Clean Agent Directories
almtcger commented 6 years ago

Hi Joe,

could you please run your build again with the variable System.Debug set to true and post the log? Make sure to remove all sensitive data or data you do not want to display here from the log or send the log to PSGerExtSupport@microsoft.com. With the additional information we should be able to quickly resolve the issue.

René

camp-007 commented 6 years ago

Here is the log for that step/task with System.Debug = true

2018-05-15T20:25:06.1518358Z ##[debug]Evaluating condition for step: 'Clean Agent Directories'
2018-05-15T20:25:06.1518358Z ##[debug]Evaluating: succeeded()
2018-05-15T20:25:06.1518358Z ##[debug]Evaluating succeeded:
2018-05-15T20:25:06.1518358Z ##[debug]=> (Boolean) True
2018-05-15T20:25:06.1518358Z ##[debug]Expanded: True
2018-05-15T20:25:06.1518358Z ##[debug]Result: True
2018-05-15T20:25:06.1518358Z ##[section]Starting: Clean Agent Directories
2018-05-15T20:25:06.1518358Z ==============================================================================
2018-05-15T20:25:06.1518358Z Task         : Post Build Cleanup
2018-05-15T20:25:06.1518358Z Description  : Cleans the build directories on the agent after the build has finished.
2018-05-15T20:25:06.1518358Z Version      : 3.0.1
2018-05-15T20:25:06.1518358Z Author       : Microsoft Premier Services
2018-05-15T20:25:06.1518358Z Help         : [More information](https://github.com/almtcger/VstsExtensions/blob/master/PostBuildCleanup/en-US/overview.md)
2018-05-15T20:25:06.1518358Z ==============================================================================
2018-05-15T20:25:06.5424616Z ##[debug]agent.workFolder=C:\BuildAgent\2\_work
2018-05-15T20:25:06.5580892Z ##[debug]loading inputs and endpoints
2018-05-15T20:25:06.5580892Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2018-05-15T20:25:06.5580892Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2018-05-15T20:25:06.5580892Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2018-05-15T20:25:06.5580892Z ##[debug]loading INPUT_DISABLECERTCHECK
2018-05-15T20:25:06.5580892Z ##[debug]loading SECRET_SQLPASSWORD
2018-05-15T20:25:06.5580892Z ##[debug]loaded 5
2018-05-15T20:25:06.8862252Z ##[debug]check path : C:\BuildAgent\2\_work\_tasks\PostBuildCleanup_175c8a10-0ef0-11e7-936d-2100de00518d\3.0.1\task.json
2018-05-15T20:25:06.8862252Z ##[debug]set resource file to: C:\BuildAgent\2\_work\_tasks\PostBuildCleanup_175c8a10-0ef0-11e7-936d-2100de00518d\3.0.1\task.json
2018-05-15T20:25:06.8862252Z ##[debug]system.culture=en-US
2018-05-15T20:25:06.8862252Z ##[debug]disableCertCheck=false
2018-05-15T20:25:06.9018577Z SystemVssConnection exists true
2018-05-15T20:25:06.9018577Z ##[debug]SystemVssConnection exists true
2018-05-15T20:25:06.9018577Z ##[debug]System.TeamFoundationCollectionUri=https://******Account********.visualstudio.com/
2018-05-15T20:25:06.9018577Z ##[debug]PBC.LogRawData=undefined
2018-05-15T20:25:06.9018577Z ##[debug]System.TeamProject=******TeamProjectName*******
2018-05-15T20:25:06.9018577Z ##[debug]System.DefinitionId=120
2018-05-15T20:25:06.9018577Z ##[debug]Build.DefinitionVersion=10
2018-05-15T20:25:06.9018577Z ##[debug]Build.BuildId=39673
2018-05-15T20:25:06.9018577Z ##[debug]System.JobId=df143ba0-1c7a-5b21-02e1-d41a394e29c9
2018-05-15T20:25:06.9018577Z ##[debug]System.PhaseDisplayName=Phase 1
2018-05-15T20:25:06.9018577Z ##[debug]System.JobDisplayName=Job
2018-05-15T20:25:06.9018577Z ##[debug]PSGer.Build.PollInterval=undefined
2018-05-15T20:25:06.9018577Z ##[debug]PSGer.Build.MaxWaitTime=undefined
2018-05-15T20:25:06.9018577Z ##[debug]isLastTaskInCurrentPhase
2018-05-15T20:25:06.9018577Z ##[debug]getBuildJobRecords
2018-05-15T20:25:06.9018577Z ##[debug]prepareClients
2018-05-15T20:25:07.4800334Z Cannot read property 'id' of null
2018-05-15T20:25:07.4956006Z ##[section]Finishing: Clean Agent Directories
almtcger commented 6 years ago

Thanks for sharing the log. I found the issue and it is related to post job scripts. Those scripts run after all other tasks and break our logic to check if the PostBuildCleanup task is the last task in the phase. I should have a fix ready by tomorrow.

René

almtcger commented 6 years ago

Hey Joe,

I just pushed v3.0.4 of the task to the marketplace. This version should fix your issue. If the issue still persists or you have any other questions or feedback, just let us know here, via email, or use the rating or Q&A feature of the marketplace.

Happy building! René

camp-007 commented 6 years ago

I'm no longer getting that error, however, it does not appear to be working. I checked the agent machine afterwards and I still had all the source files. Should the logs give any more messages indicating folders were cleaned? Or do these logs look correct to you?

2018-05-22T21:49:07.3245425Z ##[section]Starting: Clean Agent Directories
2018-05-22T21:49:07.3248361Z ==============================================================================
2018-05-22T21:49:07.3248517Z Task         : Post Build Cleanup
2018-05-22T21:49:07.3248638Z Description  : Cleans the build directories on the agent after the build has finished.
2018-05-22T21:49:07.3248767Z Version      : 3.0.5
2018-05-22T21:49:07.3248874Z Author       : Microsoft Premier Services
2018-05-22T21:49:07.3249004Z Help         : [More information](https://github.com/almtcger/VstsExtensions/blob/master/PostBuildCleanup/en-US/overview.md)
2018-05-22T21:49:07.3249142Z ==============================================================================
2018-05-22T21:49:07.7878530Z SystemVssConnection exists true
2018-05-22T21:49:08.4044832Z ##[section]Finishing: Clean Agent Directories
almtcger commented 6 years ago

Hi Joe,

you need to look at the post-job script log instead of the task log. In order to run the cleanup after all other build steps, I needed to move the cleanup logic to a post-job script.

How did you configure the clean option of your build? If you're using Git and have the clean option set to sources, we will simply run git clean and git reset --hard HEAD for the repo and all submodules. This is the same logic the build agent uses when cleaning sources at the beginning of the build.

If you want to fully remove all sources, you need to set the clean option to sources directory.

Hope that helps, René

camp-007 commented 6 years ago

I see the logs now in the post job step. I can verify it is running the same git command as the beginning of the build. Looks like it is working perfectly! Thanks for your responsiveness!

almtcger commented 6 years ago

Hey, thanks for the update. I'm glad we got you unblocked. Feel free to contact us again if there are any additional issues or questions.

René