Skip to content

Windows build node SSH connection issue using JCasC #242

@robinbanbury

Description

@robinbanbury

When configuring a Windows agent using JCasC, the SSH connection is broken between Jenkins and the agent if 'username/password' authentication is selected.

Windows agent configuration:

- namePrefix: gce-windows-vm
    description: Windows VM running in GCE
    labelString: gce-windows-vm
    template: "https://www.googleapis.com/compute/v1/projects/${projectID}/global/instanceTemplates/jenkins-windows-vm"
    remoteFs: C:\Users\jenkins
    windowsConfiguration:
      passwordCredentialsId: user-pass-credential-id
    retentionTimeMinutesStr: 6
    mode: EXCLUSIVE
    numExecutorsStr: 1
    launchTimeoutSecondsStr: 300
    useInternalAddress: true
    runAsUser: jenkins
    javaExecPath: java
    oneShot: true
    region: "https://www.googleapis.com/compute/v1/projects/${projectID}/regions/${region}"
    zone: "https://www.googleapis.com/compute/v1/projects/${projectID}/zones/${zone}"

The configuration looks suitable when examined in the Jenkins UI, but I can see the following error in the agent logs:

Feb 25, 2021 10:23:16 AM null
WARNING: Failed to authenticate with exception:  Exception: java.lang.NullPointerException

On a closer inspection in the system logs:

Feb 25, 2021 10:44:19 AM WARNING com.google.jenkins.plugins.computeengine.ComputeEngineCloud log
Failed to authenticate with exception: 
java.lang.NullPointerException
	at com.google.jenkins.plugins.computeengine.ComputeEngineWindowsLauncher.authenticateSSH(ComputeEngineWindowsLauncher.java:72)
	at com.google.jenkins.plugins.computeengine.ComputeEngineWindowsLauncher.bootstrap(ComputeEngineWindowsLauncher.java:104)
	at com.google.jenkins.plugins.computeengine.ComputeEngineWindowsLauncher.setupConnection(ComputeEngineWindowsLauncher.java:56)
	at com.google.jenkins.plugins.computeengine.ComputeEngineComputerLauncher.launch(ComputeEngineComputerLauncher.java:301)
	at com.google.jenkins.plugins.computeengine.ComputeEngineComputerLauncher.launch(ComputeEngineComputerLauncher.java:224)
	at hudson.slaves.SlaveComputer.lambda$_connect$0(SlaveComputer.java:296)
	at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
	at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Looking at that line in the code, it seems that windowsConfig.getPrivateKeyCredentialsId() can return a null value, so call isEmpty() on that will cause the NPE.

Workaround is to specify an empty string as the privateKeyCredentialsId, e.g.

  windowsConfiguration:
    privateKeyCredentialsId: ""
    passwordCredentialsId: user-pass-credential-id

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions