我使用Jenkins Multiple SCM插件将两个git存储库签出到我的Jenkins作业中的两个子目录中。然后,我执行一组命令,使用从所有三个存储库提取的信息和代码构建一组工件。但是分支测试被检查了两次?工作区具有当前结构:
root
-.git
-all other files
-test
-res我希望工作区具有这样的结构。
root
-test
-res node (label: 'YYY'){
checkout([
$class: 'GitSCM',
branches: [[name: '*/test']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'test']],
submoduleCfg: [],
userRemoteConfigs: [[url: 'http://myrepo.git']]
])
dir('res') {
git branch: 'master', url: 'http://newrepo.git'
}
}
pipeline {
agent { label 'YYY' }
stages {
xxx
}
}发布于 2020-07-16 15:48:31
为此,我使用了一个函数:
def checkoutGitRepo(final String repoUrl, final String repoBranch, final String folder) {
//checkout in folder
dir ("${folder}") {
git(url: "${repoUrl}",
credentialsId: 'jenkins-git-credential-id-here',
branch: "${repoBranch}"
)
}
}您可以将该函数放在一个共享库中,并在需要的任何构建中调用它。
发布于 2020-07-16 17:06:28
你可以像这样克隆多个repos:
stage('Setup workspace') {
dir('proj1') {
git([url: 'git@gitlab.xxx.local:chenchuk/proj1.git', branch: 'master'])
}
dir('proj2') {
git([url: 'git@gitlab.xxx.local:chenchuk/proj2.git', branch: 'master'])
}
}虽然这不在问题中,但值得一提的是,它也可以并行进行,如下所示:
stage('Setup workspace') {
parallel('clone projects': {
dir('proj1') {
git([url: 'git@gitlab.xxx.local:chenchuk/proj1.git', branch: 'master'])}
}, 'clone sf_tasks': {
dir('proj2') {
git([url: 'git@gitlab.xxx.local:chenchuk/proj2.git', branch: 'master'])}
})
}https://stackoverflow.com/questions/62929517
复制相似问题