Skip to content

AllFunctions.ps1 : curl.exe fails with NativeCommandError in Jenkins #73

Description

@andreacuozzo

OSDBuilder version; 21.12.15.1

Command:

Update-OSMedia -execute -Name Windows Server 2019 Datacenter Desktop Experience x64 1809 17763.379 -Download 
-Include SSU,LCU,DotNetCU,AdobeSU

Scenario: I'm using Jenkins to run a powershell script on a remote host. The Update-OSMedia fails with the error below, because the Jenkins environment doesn't handle well the output generated by the curl.exe call in AllFunctions.ps1 starting on line 3054:

if (Get-Command 'curl.exe' -ErrorAction SilentlyContinue) {
    Write-Verbose "cURL: $SourceUrl"
    if ($host.name -match 'ConsoleHost') {
        Invoke-Expression "& curl.exe --insecure --location --output `"$DownloadFullPath`" --url `"$SourceUrl`""
           }
    else {
         #PowerShell ISE will display a NativeCommandError, so progress will not be displayed
         $Quiet = Invoke-Expression "& curl.exe --insecure --location --output `"$DownloadFullPath`" --url `"$SourceUrl`" 2>&1"
            }

Error:

WSUSXML (Microsoft Updates) Download
07/14/2020 17:00:00 - DotNetCU - 2020-07 Cumulative Update for .NET Framework 3.5 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4566516)
C:\Build\OSDBuilder\Windows2019\Updates\windows10.0-kb4565632-x64-ndp48_8b481763cf07efc55f729bb1e08dc9fe32d3237a.cab
http://download.windowsupdate.com/c/msdownload/update/software/secu/2020/06/windows10.0-kb4565632-x64-ndp48_8b481763cf07efc55f729bb1e08dc9fe32d3237a.cab
C:\Windows\system32\windowspowershell\v1.0\powershell.exe : curl.exe :   % Total    % Received % Xferd  Average Speed  
 Time    Time     Time  Current
At C:\Users\test\AppData\Local\Temp\jenkins6057044616296770173.ps1:2 char:1
+ C:\Windows\system32\windowspowershell\v1.0\powershell.exe -File C:\bu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (curl.exe :   % ...  Time  Current:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Workaround (there might be other ones better than this):

the code runs through the ($host.name -match 'ConsoleHost') path, and fails here:

Invoke-Expression "& curl.exe --insecure --location --output "$DownloadFullPath" --url "$SourceUrl""

the workaround is to force it to run through the other "ISE quiet" path that handles the curl.exe output:

$Quiet = Invoke-Expression "& curl.exe --insecure --location --output "$DownloadFullPath" --url "$SourceUrl" 2>&1"

It's been months since I've last used this script of mine, it was working fine on previous OSDBuilder versions: my scenario (Jenkins agent running a script remotely) might be a corner case unworhty of being investigated and fixed, just my 2 cents should anyone else have the same problem.

Andrea

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions