I have a system which executes a bunch of DSC configurations on a nightly basis to build out machines. This is initiated by a scheduled job (MultiJob) in Jenkins. The schedule job then triggers individual jobs and waits for all jobs to complete. 90% of the time this works without an issue.
However, occasionally one of the individual jobs requires a reboot. This is configured correctly with the LCM and using the xPendingReboot DSC resource. No issues here.
The problem is the PowerShell Job that is executing on the target machine ends when the reboot is initiated. This then triggers the next stage of the build process which fails because the DSC process is actually not yet complete.
Does anyone out there know how to reacquire pending DSC job on the target machine after it has been rebooted?
Update (untested): Currently working on a scenario that invokes the GetCimSessionInstanceId method on the LCM to acquire the session handle when the job completes. This session id can then be used to reacquire the CimSession on the remote machine after the reboot via the Get-CimSession cmdlet. My assumption is that I'll be able to remotely execute Get-Job on the cim session to determine if the DSC process has continued. This leads to an additional question. How can we determine that the initial dsc job ended due to a reboot or if it is actually the end of the process?
This approach should work for what you are looking for http://nanalakshmanan.github.io/blog/DSC-get-job-details-post-reboot/
In cases where you want to obtain the information from the node post a reboot, set DSC to not proceed after reboot. This can be done by using the following meta configuration sample
[DscLocalConfigurationManager()]
Configuration Settings
{
Settings
{
ActionAfterReboot = 'StopConfiguration'
RebootNodeIfNeeded = $false
}
}
Then re-apply the existing configuration using the following command
Start-DscConfiguration -Wait -UseExisting -Verbose