首页 > 解决方案 > 在詹金斯工作中动态选择git repo

问题描述

在 jenkins 工作中,是否可以有多个 git 存储库并根据参数动态选择存储库?

标签: gitjenkins

解决方案


您可以在 jenkins 管道中设置 git URL,如下所示

pipeline {
    agent any


    parameters { 
        string(defaultValue: "https://github.com", description: 'Whats the github URL?', name: 'URL')
    }


    stages {
        stage('Checkout Git repository') {
           steps {
                git branch: 'master', url: "${params.URL}"
            }
        }

        stage('echo') {
           steps {
                echo "${params.URL}"
            }
        }
    }
}

那是使用git步骤此处说明

如果您需要检出多个Git 存储库,也可以根据子文件夹进行设置。


推荐阅读