jenkins - 使用 Jenkins 管道将多个 git 存储库检出到子目录中
问题描述
我正在使用 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
}
}
解决方案
我为此使用了一个函数:
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}"
)
}
}
您可以将该函数放在共享库中,并在您需要的任何构建中调用它。
推荐阅读
- html - SCSS Mixin 无法编译
- python - 如何在熊猫中查找某些列变量的行
- javascript - 允许在页面加载时播放音频
- python - 将输出写入不同的 csv 文件列
- python - 从 numpy 数组在 PyQt5 中显示图像
- python - 如何修复 sklearn for python 安装失败
- android-studio - 在 Google Play 商店中上传 Ionic 项目的错误
- python - 尝试创建 Twitter 情绪分析,我收到此错误 AttributeError: 'str' object has no attribute 'csv'
- python - 在 Pandas 列中过滤列表中的项目
- r - 使用R中的函数从服务器下载数据时利用for循环?