On my Jenkins pipeline job, I used to clone git repo at the begining of my job like that
cleanWs()
git branch: 'master', credentialsId: 'SSH_GIT', url: 'git@myserver.com:myrepo'
Note that I need credentials.
In order to reduce time execution and data size downloaded, I would like to use git archive
instead of git clone
.
sh("git archive --format=tar --remote git@myserver.com:myrepo master |tar xf -")
The previous command works if I have proper ssh-key configuration done. It is not the case on my server, so I need to use credentials.
How can I archive instead of cloning repo, using Jenkins defined credentials ? Git is installed on a gitolite server
The solution is to use sshagent function in Jenkins Pipeline
sshagent(['SSH_JENKINS_CREDENTIALS_FOR_GIT']) {
sh("git archive --format=tar --remote git@myserver.com:myrepo master |tar xf -")
}