How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

October 07, 2022


There are some cases, where I need another git repository while running some automation. Lets see, how we can clone another git repository within another job.

Jenkinsfile for Git Clone

stage('Get K8s Yaml files') {
    steps {
        echo 'Getting kubernetes files from git...'

        checkout([$class: 'GitSCM', 
            branches: [[name: '*/main']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[
                $class: 'RelativeTargetDirectory',
                relativeTargetDir: 'k8s_deployment']],
            submoduleCfg: [], 
            userRemoteConfigs: [[
                credentialsId: 'my-git-token',
                url: '']]])

In above Jenkinsfile, I’m asking Jenkin to clone the git repository in a directory: k8s_deployment, and this directory will be created in the workspace directory. I will also need the git token.

Similar Posts

Latest Posts