Jenkinsfile with two git repositories

前端 未结 2 1596
囚心锁ツ
囚心锁ツ 2020-12-15 05:48

I\'m using the Jenkins pipeline plugin with a Jenkinsfile.

In one repository, called vms.git, I have the Jenkinsfile and an application it builds.

I have a

相关标签:
2条回答
  • 2020-12-15 06:08

    You can checkout multiple directories using checkout, but you have to specify directory where you want checkout this. You can generate snippets using jenkins (Snippet generator bellow script field). Choose checkout, next git repository and in Additional Behaviours choose: checkout into sub directory.

    When you will have 2 repositories you can load script from repository you want usin load. Example:

    node {
        // first repository
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory1']], submoduleCfg: [], userRemoteConfigs: [[url: 'repo1.git']]])
        // second repository
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory2']], submoduleCfg: [], userRemoteConfigs: [[url: 'repo2.git']]])
        // run first script
        load 'subdirectory1/Jenkinsfile'
        // run second script
        load 'subdirectory2/Jenkinsfile'
    }
    
    0 讨论(0)
  • 2020-12-15 06:29

    Another elegant solution for handling multiple Git repositories within single pipeline can be found at this thread.

    node {
        dir('RepoOne') {
            git url: 'https://github.com/somewhere/RepoOne.git'
        }
        dir('RepoTwo') {
            git url: 'https://github.com/somewhere/RepoTwo.git'
        }
    
        sh('. RepoOne/build.sh')
        sh('. RepoTwo/build.sh')
    }
    
    0 讨论(0)
提交回复
热议问题