powershelljenkins

Jenkins always logs a RemoteException when running powershell script. How can I understand and prevent the exception?


I have a Jenkins instance and multiple Windows 10 agents running on Azure VMs. Every time I run a powershell script in a pipeline, I get the following in my logs:

powershell.exe : Unable to retrieve boot drive serial number
At C:\Users\myuser\mypath@tmp\durable-fc650d61\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unable to retri...e serial number:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

(C:\Users\myuser\mypath is an example path, not a real path).

I suspect that the cause of the issue is that the Azure VMs obscure or do not have boot drive serial numbers, but it is not clear to me why Jenkins or Powershell even care about this.

For what it's worth, this error does not cause my scripts to fail - it is simply annoying noise in the logs.

How can I prevent either: the log, or the exception from happening in the first place?

Edit: To clarify, this only happens if I pass a ps1 file path to the powershell directive, for example:

powershell "./path/to/my/script/ps1"

It does not happen if I pass a script inline.


Solution

  • Upon further investigation, it seems the exception is not being caused by Jenkins or Powershell - it is a third-party CLI throwing the exception.

    I was misled by the output in Jenkins masking the actual source of the exception (this is probably a Jenkins thing). I solved it by investigating the problematic scripts and looking for commonalities, then reproduced it directly on the VM.