Slave Container accessing GitHub private repository via SSH keys

33 views
Skip to first unread message

Matthew Ceroni

unread,
Feb 21, 2017, 1:48:56 PM2/21/17
to Jenkins Users
Running into issues checking out a private repository within a slave container. 

To start, I created a SSH username + private key credential. The private key has been verified to work against the GitHub organization I am attempting to clone repositories from.

My pipeline looks like such:

import groovy.json.JsonSlurper

@NonCPS
def parseResponse(response) {
    def list = new JsonSlurper().parseText( response )
    
    def repositories = []
    for (Map item : list) {
        repositories.push(item.ssh_url)
        //println "${item.ssh_url}"
    }
    return repositories
}

podTemplate(label: 'mypod', containers: [
    containerTemplate(name: 'golang', image: 'golang:1.6.3', ttyEnabled: true, command: 'cat')
  ]) {
    
    node ('mypod') {
        stage 'Find Repositories'
        
        // make call to GitHub API to list all repositories for project
        def response = httpRequest "https://api.github.com/teams/xxxx/repos?access_token=xxxxx"
        
        // parse the response and write out a file containing the list of repositories
        def repositories = parseResponse(response.content)
        
        container('golang') {
            stage 'Checkout Repositories'
            
            for (String item : repositories) {
                git branch: 'master', credentialsId: '7f66557f-8ee3-4d69-b271-f8b1bbfa02b0', url: item
                println item
            }
            
            sh """
            sleep 600
            """
            
        }

    }
}

Basically, I query all the repositories that are part of a team and then want to loop over those and perform some action. But the git call fails with the following:

[Pipeline] git
Cloning the remote Git repository
Cloning repository g...@github.com:XXXXX/activeMqMessageQueueing.git
 > git init /home/jenkins/workspace/DevOps/git-hooks # timeout=10
Fetching upstream changes from g...@github.com:XXXXXX/activeMqMessageQueueing.git
 > git --version # timeout=10
using GIT_SSH to set credentials s-automation GitHub SSH key
 > git fetch --tags --progress g...@github.com:XXXXX/activeMqMessageQueueing.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress g...@github.com:XXXX/activeMqMessageQueueing.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: /tmp/ssh7121108186801417889.sh: line 6: ssh: not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


So it appears to set the credentials correctly (using GIT_SSH to set credentials to s-automation GitHub SSH key) but then complains SSH not found. The container that this part of the pipeline runs in has SSH so not sure why it would complain about that. I would love to be able to see what is in  /tmp/ssh7121108186801417889.sh but the job fails and the container dies at that point.

Kind of stuck where to go from here. Any assistance would be appreciated.

Thanks

Reply all
Reply to author
Forward
0 new messages