Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65401

Finding an SSH provider times out when Jenkins server is on Windows and agent is running in a docker container

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • ssh-agent-plugin
    • Jenkins Server: Windows 2012 R2, Jenkins 2.263.4, ssh-agent-plugin 1.22
      Agents: jenkins/inbound-agent:4.3-4 Docker container running under Kubernetes client version 1.16.8 and server version 1.17.5.

      This Jenkinsfile:

      pipeline {
        agent {
          kubernetes {
            label '********-' + UUID.randomUUID().toString()
            yaml """
      apiVersion: v1
      kind: Pod
      spec:
        securityContext:
          runAsUser: 0
          fsGroup: 0
        containers:
        - name: aws
          image: amazon/aws-cli
          tty: true
          command: ["cat"]
        - name: docker
          image: docker:stable-git
          tty: true
          command: ["cat"]
          volumeMounts:
          - mountPath: /var/run/docker.sock
            name: docker-socket
        volumes:
        - name: docker-socket
          hostPath:
            path: /var/run/docker.sock
      """
          }
        }
      
        parameters {
          string(name: 'SOURCE_BRANCH', defaultValue: '*********', description: '**********')
        }
      
        environment {
          DEPLOY_SOURCE         = "git@bitbucket.org:***********/************.git"
        }
      
        stages {
          stage('SSH Prep') {
            steps {
              container('docker') {
                sh 'mkdir -p ~/.ssh && chmod 700 ~/.ssh'
                sh 'for i in 1 2 3 4 5; do ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts && break; done'
                sh 'ssh-keyscan -t rsa ************* >> ~/.ssh/known_hosts'
              }
            }
          }
          stage('Clone Source') {
            steps {
              container('docker') {
                sshagent (credentials: ['id_rsa_to_bitbucket_org']) {
                  sh 'git clone -b $SOURCE_BRANCH $DEPLOY_SOURCE source'
                }
              }
            }
          }
        }
      }
      

      times out on the ssagent step:

      [Pipeline] container
      [Pipeline] {
      [Pipeline] sshagent
      [ssh-agent] Using credentials ******** (******** Private Key (for Git to Bitbucket Server).)
      [ssh-agent] Looking for ssh-agent implementation...
      ERROR: Timeout after 1 minutes
      [ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
      Executing sh script inside container docker of pod ********-ca487127-2c12-4fa4-bef6-db46df3736ec-gvnmh-w1927
      Executing command: "ssh-agent" 
      exit
      
      : No such file or directory
      sh: exit
      : not found
      ERROR: Timeout after 1 minutes
      [ssh-agent] FATAL: Could not find a suitable ssh-agent provider
      [ssh-agent] Diagnostic report
      [ssh-agent] * Exec ssh-agent (binary ssh-agent on a remote machine)
      [ssh-agent]     java.lang.StringIndexOutOfBoundsException: begin 13, end -1, length 50
      
      [ssh-agent]     	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
      
      [ssh-agent]     	at java.base/java.lang.String.substring(String.java:1874)
      
      [ssh-agent]     	at com.cloudbees.jenkins.plugins.sshagent.exec.ExecRemoteAgent.getAgentValue(ExecRemoteAgent.java:156)
      

      (full stack trace omitted for brevity).

      However, this only happens when Jenkins server is running on Windows 2012 R2. When the Jenkins server runs on Linux (I believe Ubuntu), the sshagent command succeeds.

      I've attached the Kubernetes .yml file for the Jenkins agent, and the full output from Jenkins.

       

            Unassigned Unassigned
            splatteredbits Aaron Jensen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: