Nonspecific error when when building lighting via commandlet

I’m trying to setup automated lightmap builds for my project as part of our TeamCity build process. The project successfully uses RunUAT to perform build/cook operations, but I haven’t been able to get any approach for building lighting to work.

LogContentCommandlet: Error: [REPORT] Failed building lighting for /Game/Maps/NewMap

LogStaticLightingSystem: Warning: Failed to build lighting!!! Lighting build failed.

I’ve reproduced these problems in a completely blank project, created in UE 4.21.2.
This is the log output from the build machine, running UE4Editor.exe with the arguments allowcommandletrendering, run=resavepackages and buildlighting.

E: Step 2/5: Build Lightmap Test (Command Line) (7s)
 :	 [Step 2/5] Starting: C:\UE4\UE_4.21\Engine\Binaries\Win64\UE4Editor.exe D:\TeamCity-BuildAgent-2\work\a810b588373951b6\BuildTest.uproject -run=resavepackages -buildlighting -mapsonly -projectonly -allowcommandletrendering -messaging -map=NewMap
 :	 [Step 2/5] in directory: D:\TeamCity-BuildAgent-2\work\a810b588373951b6
 :	 [Step 2/5] [2019.05.08-01.59.38:140][  0]LogStreaming: Display: Took  0.333s to InitEngineTextLocalization.
 :	 [Step 2/5] [2019.05.08-01.59.38:579][  0]LogTemp: Display: Loaded TP AllDesktopTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:589][  0]LogTemp: Display: Loaded TP MacClientTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:599][  0]LogTemp: Display: Loaded TP MacNoEditorTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:610][  0]LogTemp: Display: Loaded TP MacServerTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:621][  0]LogTemp: Display: Loaded TP MacTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:631][  0]LogTemp: Display: Loaded TP WindowsClientTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:642][  0]LogTemp: Display: Loaded TP WindowsNoEditorTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:652][  0]LogTemp: Display: Loaded TP WindowsServerTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:658][  0]LogTemp: Display: Loaded TP WindowsTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:716][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:717][  0]LogTemp: Display: Loaded TP AndroidTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:718][  0]LogTemp: Display: Loaded TP HTML5TargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:773][  0]LogTemp: Display: Loaded TP IOSTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:773][  0]LogTemp: Display: Loaded TP IOSTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:791][  0]LogTemp: Display: Loaded TP TVOSTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:791][  0]LogTemp: Display: Loaded TP TVOSTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:801][  0]LogTemp: Display: Loaded TP LinuxClientTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:811][  0]LogTemp: Display: Loaded TP LinuxNoEditorTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:821][  0]LogTemp: Display: Loaded TP LinuxServerTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:830][  0]LogTemp: Display: Loaded TP LinuxTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:867][  0]LogTemp: Display: Loaded TP LuminTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:868][  0]LogTemp: Display: Loaded TP LuminTargetPlatform
 :	 [Step 2/5] [2019.05.08-01.59.38:868][  0]LogTargetPlatformManager: Display: Building Assets For Windows
 :	 [Step 2/5] [2019.05.08-01.59.38:923][  0]LogShaderCompilers: Display: Using XGE Shader Compiler (Interception Interface).
 :	 [Step 2/5] [2019.05.08-01.59.39:385][  0]LogDerivedDataCache: Display: Max Cache Size: 512 MB
 :	 [Step 2/5] [2019.05.08-01.59.39:415][  0]LogDerivedDataCache: Display: Loaded Boot cache: C:/Windows/system32/config/systemprofile/AppData/Local/UnrealEngine/4.21/DerivedDataCache/Boot.ddc
 :	 [Step 2/5] [2019.05.08-01.59.39:429][  0]LogDerivedDataCache: Display: Pak cache opened for reading ../../../Engine/DerivedDataCache/Compressed.ddp.
 :	 [Step 2/5] [2019.05.08-01.59.40:727][  0]LogGameplayTags: Display: UGameplayTagsManager::DoneAddingNativeTags. DelegateIsBound: 0
 :	 [Step 2/5] [2019.05.08-01.59.40:867][  0]LogContentCommandlet: Display: Loading D:/TeamCity-BuildAgent-2/work/a810b588373951b6/Content/Maps/NewMap.umap
 :	 [Step 2/5] [2019.05.08-01.59.41:081][  0]LogContentCommandlet: Error: [REPORT] Failed building lighting for /Game/Maps/NewMap
 :	 [Step 2/5] [2019.05.08-01.59.41:081][  0]LogStaticLightingSystem: Warning: Failed to build lighting!!! Lighting build failed.
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogContentCommandlet: Display: [REPORT] 1/1 packages required resaving
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogInit: Display: 
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogInit: Display: Warning/Error Summary (Unique only)
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogInit: Display: -----------------------------------
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogInit: Display: LogContentCommandlet: Error: [REPORT] Failed building lighting for /Game/Maps/NewMap
 :	 [Step 2/5] [2019.05.08-01.59.41:142][  0]LogInit: Display: LogStaticLightingSystem: Warning: Failed to build lighting!!! Lighting build failed.
 :	 [Step 2/5] [2019.05.08-01.59.41:143][  0]LogInit: Display: 
 :	 [Step 2/5] [2019.05.08-01.59.41:143][  0]LogInit: Display: Failure - 1 error(s), 1 warning(s)
 :	 [Step 2/5] [2019.05.08-01.59.41:143][  0]LogInit: Display: 
 :	 [Step 2/5] 
 :	 [Step 2/5] Execution of commandlet took:  0.33 seconds
 :	 [Step 2/5] [2019.05.08-01.59.41:399][  0]LogShaderCompilers: Display: Shaders left to compile 0
W:	 [Step 2/5] Process exited with code 1
E:	 [Step 2/5] Process exited with code 1 (Step: Build Lightmap Test (Command Line))
E:	 [Step 2/5] Step Build Lightmap Test (Command Line) failed

At the same time as this, the Swarm agent log on the build server produces this log.

11:59:41 AM: [Interface:TryOpenConnection] Local connection established
11:59:41 AM: [Interface:OpenJob] Error: Value cannot be null.
Parameter name: value
11:59:41 AM: [MaintainConnections] Detected dropped local connection, cleaning up (245E4B58)
11:59:41 AM: [CloseConnection] Closing connection 245E4B58 using handle 245E4B58
11:59:41 AM: [CloseConnection] Connection confirmed for disconnection 245E4B58
11:59:41 AM: [FlushMessageQueue] Draining message queue for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock acquired for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock released for 245E4B58
11:59:41 AM: [FlushMessageQueue] Drain complete for 245E4B58
11:59:41 AM: [CloseConnection] Closing orphaned Job ()
11:59:41 AM: [FlushMessageQueue] Draining message queue for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock acquired for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock released for 245E4B58
11:59:41 AM: [FlushMessageQueue] Drain complete for 245E4B58
11:59:41 AM: [PostJobStatsToDB] Database error:
11:59:41 AM: [PostJobStatsToDB] Object reference not set to an instance of an object.
11:59:41 AM: [FlushMessageQueue] Draining message queue for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock acquired for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock released for 245E4B58
11:59:41 AM: [FlushMessageQueue] Drain complete for 245E4B58
11:59:41 AM: [FlushMessageQueue] Draining message queue for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock acquired for 245E4B58
11:59:41 AM: [FlushMessageQueue] Lock released for 245E4B58
11:59:41 AM: [CloseConnection] Connection disconnected 245E4B58
11:59:41 AM: [FlushMessageQueue] Drain complete for 245E4B58
11:59:41 AM: [GetMessage] Safely returning to 245E4B58 with no message
11:59:41 AM: [MaintainConnections] Local connection has closed (245E4B58)
11:59:41 AM: [MaintainConnections] Removed connection 245E4B58
11:59:41 AM: [MaintainConnections] All connections have closed

I have also tried using RunUAT directly with the RebuildLightmaps argument, but it just complains about me not using P4

Running AutomationTool...
Parsing command line: RebuildLightmaps
WARNING: Command RebuildLightMaps requires P4 functionality.
WARNING: P4PORT is not set. Using perforce:1666
  Perforce client error:
        Connect to server failed; check $P4PORT.
        TCP connect to perforce:1666 failed.
        No such host is known.
ERROR: Perforce command failed: Perforce client error:
        Connect to server failed; check $P4PORT.
        TCP connect to perforce:1666 failed.
        No such host is known.
       . Please make sure your P4PORT or uebp_PORT is set properly.
       (see C:\UE4\UE_4.21\Engine\Programs\AutomationTool\Saved\Logs\Log.txt for full exception trace)

In case anyone else runs into this, I did eventually find the problem in the Swarm agent. There was an error code being generated then suppressed which indicated the swarm had connectivity problems. After fixing those the lightmap build could continue.

I’m having the similar log of:
[Interface:OpenJob] Error: Value cannot be null.
Parameter name: value

What did you do to fix it / how could you see the suppressed error code?