SSH Agent

SSH Agent

node {
    step([$class: 'WsCleanup'])
    sshagent(['ssh']) {
        git branch: 'test', url: 'https://github.com/nrayapati/kcdc_test.git'
        sh "ssh-keyscan -H github.com >> ~/.ssh/known_hosts"
        sh "git remote set-url origin git@github.com:nrayapati/kcdc_test.git"
        sh "git config user.email naresh.rayapati@gmail.com"
        sh "git config user.name nrayapati"
        sh 'git checkout -b kcdc'
        sh 'git push origin kcdc'
    }
}

Commands to generate key:

https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

# Copy public key to your account on github
pbcopy < ~/.ssh/id_rsa.pub

# Save private key in Jenkins
pbcopy < ~/.ssh/id_rsa