2

We recently got some new Windows Server 2019 machines and I want to add them to our Jenkins setup. The problem is: executing any external program causes an error. docker login, git status, java -version all give an error like this

[TestPowershell] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\XXX~1\AppData\Local\Temp\3\jenkins1416755497082623783.ps1'"
java : java version "1.8.0_101"
At C:\Users\XXX-sa\AppData\Local\Temp\3\jenkins1416755497082623783.ps1:1 char:1
+ java -version
+ ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (java version "1.8.0_101":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Java(TM) SE Runtime Environment (build 1.8.0_101-b13
)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Notifying upstream projects of job completion
Finished: SUCCESS

Tried it on the server itself, works fine. All the setup is the same as our 2016 servers, which dont present this issue

EDIT: I setup a vanilla master on VM 2019 and it works without this error, still presents the error with a 2016 master.

CarlMc
  • 210
  • 2
  • 11
  • check the jenkins service, under which user is it running.. ? try the same under that user... – Nirav Mistry Aug 07 '19 at 10:13
  • tried under the same user, which is an admin and it works fine on the server, only fails on jenkins. might be to do with https://devblogs.microsoft.com/powershell/windows-security-change-affecting-powershell/ but cant find that particular security patch on my server – CarlMc Aug 07 '19 at 10:29
  • 1
    Use `Start-Transcript ` to log about the environment and some other details and run the script after that check the logs .. – Nirav Mistry Aug 07 '19 at 10:54
  • EDIT: I setup a vanilla master on VM 2019 and it works without this error, still presents the error with a 2016 master. – CarlMc Aug 07 '19 at 13:32
  • I just saw your transcript file, Can you please provide part of powershell ? – Nirav Mistry Aug 08 '19 at 03:48
  • `write-host "****----****" $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) write-host "---------" $verbosePreference= $true try{ Start-Transcript java -version } catch{ write-host "error:" $_|format-table write-host "----" $_.ToString() $_.ErrorDetails $_.FullyQualifiedErrorId $_.Scriptstacktrace $_.PSMessageDetails $_.CategoryInfo write-host "--" $_|gm } write-host "logged"` – CarlMc Aug 08 '19 at 08:42
  • I am able to replicate your issue, just open powershell ISE -> new file -> write java -version and run ( press F5 ), you will receive the same error, reason : the command produce output in 2-3 lines and powershell understand it as next command.... – Nirav Mistry Aug 08 '19 at 09:33
  • your problem is similar like [this](https://stackoverflow.com/questions/28691344/how-to-call-a-java-program-from-powershell) – Nirav Mistry Aug 08 '19 at 09:47
  • @NirajGajjar I dont think thats the same issue. jenkins runs these commands fine on my 2016 slaves with the same configuration, and it works on a 2019 master. – CarlMc Aug 08 '19 at 15:04

2 Answers2

1

For some reason, it seems that this is related to dotnet 4.8. Windows 2019 1809 ships with 4.7 which presents this strange error, not only does it happen on java -version, but git clone , npm install and ng build to name a few also cause the same error. Installing dotnet framework 4.8 fixes it.. in case anyone is having the same issue we were..

CarlMc
  • 210
  • 2
  • 11
0

Per default jenkins-slave service runs under the SYSTEM user, under which e.g. git operations will fail, since the user credentials are missing.

In the Windows service control manager change the user of the jenkins-slave-service (properties - log on) the an user profile that has appropriate permissions.

Hope that helps.

Moerwald
  • 10,448
  • 9
  • 43
  • 83
  • it is running under the same admin that our 2016 servers are running. still fails – CarlMc Aug 07 '19 at 12:46
  • EDIT: I setup a vanilla master on VM 2019 and it works without this error, still presents the error with a 2016 master. – CarlMc Aug 07 '19 at 13:32
  • As @NirajGajjar suggested you should turn on PowerShell transcript, or dump at least the environment via `gci env:` in your Jenkins step. – Moerwald Aug 07 '19 at 13:34
  • I did, it didnt give me any indication on what could be the problem. – CarlMc Aug 07 '19 at 13:35