p4pratik
(Pr@+!k $#@#)
May 8, 2024, 5:43am
1
Hello all,
I m new to Jenkins and am creating a job to clone the source code over ssh. I have defined all the necessary credentials and would like to do a git clone using JenkinsFile.
I have 2 repositories and would like to clone one after the another. How can I
do that using “bat” statement / command?
download the source code in a specific directory.
I don’t want to use Pipeline with SCM
Regards
Pratik
The git plugin documentation includes an example that says:
checkout scmGit(
branches: [[name: 'v4.11.x']],
userRemoteConfigs: [[credentialsId: 'my-ssh-private-key-id',
url: 'ssh://github.com/jenkinsci/git-plugin.git']])
In a fully working declarative Pipeline to checkout one copy into my-dir-1
and another copy into my-dir-2
, that would be:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
dir('my-dir-1') {
checkout scmGit(
branches: [[name: 'v4.11.x']],
userRemoteConfigs: [[credentialsId: 'my-ssh-private-key-id',
url: 'ssh://github.com/jenkinsci/git-plugin.git']])
}
dir('my-dir-2') {
checkout scmGit(
branches: [[name: 'v4.11.x']],
userRemoteConfigs: [[credentialsId: 'my-ssh-private-key-id',
url: 'ssh://github.com/jenkinsci/git-plugin.git']])
}
}
}
}
}
If you must use a bat
command to perform the checkout from an ssh repository, then you’ll need to use the ssh-agent plugin to wrap the call to your bat
command in a block that will provide the ssh credentials for command line git.
1 Like
p4pratik
(Pr@+!k $#@#)
May 9, 2024, 6:39am
3
Hello Mark,
Thank you very much for yoru help.
I tried the same thing before posting this thread. I got an error :
“checkout” is not recognized as an internal or external command
I am using something like this:
bat “”"
checkout scmGit…
…
“”"
Will still try again and let you know.
Regards
Pratik
The message is correct. The checkout
command is a Jenkins Pipeline command, not a Windows batch file command.
p4pratik
(Pr@+!k $#@#)
May 9, 2024, 12:55pm
5
Hello Mark,
Kindly accept my apologies for the delay in reply.
After it failed, I re - tried by removing the “bat” command and tried and it worked like a charm.
With this I learnt that “checkout” is a Jenkins pipeline command and not a batch command.
Thank you very much again for your help.
Regards
Pratik
1 Like
poddingue
(Bruno Verachten)
May 13, 2024, 5:35pm
6
Thanks a lot for your feedback.