0

I've been trying to define a Jenkins pipeline that would checkout two projects from Github into two separate subdirectories of the same workspace, but unfortunately all my attempts so far are to no avail.

I found some examples that have worked for some people and tried to emulate them. They ones I used are here:

Using a Jenkins pipeline to checkout multiple git repos into same job

and here:

Is it impossible to checkout a different branch in Jenkinsfile?

And below is my complete pipeline script with two checkout variants I was trying to get to work (the dir + git is currently commented out).

The outcome is always the same, fist project checks out no problem into the designated subdirectory, then on the attempt to check out the other project the other subdirectory gets created but I get the "Avoid second fetch".

The checkout does not work on neither Mac nor on Linux. I am on Jenkins 2.277.3

Perhaps there is something obvious in there for fresh pair of eyes? Anyways I will appreciate any constructive suggestions.

def api_client_dir = 'scala-api-client'
def subject_dir = 'app-under-test'

pipeline {
    agent { label 'Mac' } //Change this to whatever your flutter jenkins nodes are labeled.
    stages {

        stage('Clean Workspace') {
            steps {
                cleanWs()
            }
        }

        stage('Checkout') {
            steps {

//                dir (subject_dir) {
//                  git credentialsId: 'github_credentials_kh', url: 'git@github.com:mygithubaccount/my-flutter-test-subject.git'
//                }
//
//                dir (api_client_dir) {
//                  git credentialsId: 'github_credentials_kh', url: 'git@github.com:mygithubaccount/my-scala-rest-client.git'
//                }

               checkout([$class: 'GitSCM',
                  branches: [[name: '*/master']],
                  doGenerateSubmoduleConfigurations: false,
                  extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: subject_dir]],
                  userRemoteConfigs: [[
                    credentialsId: 'github_credentials_kh',
                    url: 'git@github.com:mygithubaccount/my-flutter-test-subject.git'
                  ]]
               ])

               checkout([$class: 'GitSCM',
                  branches: [[name: '*/master']],
                  doGenerateSubmoduleConfigurations: false,
                  extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: api_client_dir]],
                  userRemoteConfigs: [[
                    credentialsId: 'github_credentials_kh',
                    url: 'git@github.com:mygithubaccount/my-scala-rest-client.git'
                  ]]
               ])
           }
        }
    }
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
hicnar
  • 163
  • 3
  • 9

1 Answers1

0

i was able to resolve the issue of checking out a specific branch using the noTags:False option in the GitSCM plugin.

                   checkout(
                   [
                       $class: 'GitSCM', 
                       branches: [[name: '${jenkins_branch}']],
                        extensions: [[$class: 'CloneOption', timeout: 20, noTags: false]],
                       userRemoteConfigs: [[url: '${jenkins_repo}']]
                    ]
                       )  

In your particular case you need to surround the checkout with the dir(){}

                dir ('folder1'){
                    checkout(
                           //checkout options as above
                            )                     
                 }        
                dir ('folder2'){
                    checkout(
                           //checkout options as above
                            )                     
                 }        

Hope it helps solve your problem.

  • Would you mind adding more details to your answer? why do you think your answer might work for the OP... – devmike01 Jun 21 '21 at 20:37