Skip to content

Instantly share code, notes, and snippets.

@isaaguilar
Created November 1, 2018 05:30
Show Gist options
  • Save isaaguilar/a1c7fc5db005d5dcfa7bbd710341efc7 to your computer and use it in GitHub Desktop.
Save isaaguilar/a1c7fc5db005d5dcfa7bbd710341efc7 to your computer and use it in GitHub Desktop.

Configure gitcli to use with Jenkins sh

withCredentials([
  sshUserPrivateKey(
    credentialsId: 'creds-id', 
    keyFileVariable: 'pem', 
    passphraseVariable: '', 
    usernameVariable: 'jenkins'
  )
]){
  script {
    sh '''
      cp ${pem} keyfile              
      # Configure GIT_SSH
      chmod 600 keyfile
      echo \'ssh -i \'`pwd`\'/keyfile -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $*\' > ssh
      chmod +x ssh
      export GIT_SSH="`pwd`/ssh"
    '''
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment