[英]Jenkins: How to merge some common files from one repo to another
2 repos, repo1 and repo2, having different folder structure. 2 个 repos,repo1 和 repo2,具有不同的文件夹结构。 There are some common source files exist in both repos.
两个存储库中都存在一些常见的源文件。 After successful build, need to merge changed files from the common files from repo1 to repo2.
构建成功后,需要将repo1的通用文件中的更改文件合并到repo2。
Here's what I've so far and it's not complete and I'm stuck on how to move further;到目前为止,这是我所做的,但它并不完整,我被困在如何进一步前进; is there a better way to achieve this?
有没有更好的方法来实现这一目标?
def filesNames = ""
def filesNamesList = ""
def files2push = []
def branch = env.GERRIT_PATCHSET_REVISION
//files that need to be pushed from repo1 to repo2 once build is successful
def getFileMap(file){
def repo1Repo2FileMap = [:]
def repo1Repo2FileMap = ["dir1/dir2/file1.h" : "dir1/file1.h",
"fldr1/fldr2/file2.h" : "fldr2/file2.h"
]
return repo1Repo2FileMap."$file"
}
//get changed files list
def getChanged(branch){
def headRevision = sh (script: "git ls-remote | grep refs/heads/${branch} | head -n 1 | awk \'{print \$1}\'",
returnStdout: true)
headRevision = headRevision.replaceAll("[\n\r]","")
def getChangedList = sh (
returnStdout: true,
script: "git diff --name-only $headRevision"
).trim().readLines().collect()
if(getChangedList !=""){
files = readFile(file: getChangedList)
fileName = files.readLines()
fileNameList = fileName.join(" ")
}
return changedFileNameList
}
stage("Push files to repo2"){
getChanged(branch).each{
if(getFileMap(it)){
//eg: cp dir1/dir2/file1.h dir1/file1.h
cp $file $it
files2push.add(it)
}
}
}
stage("Merge Changed files to repo2"){
dir("repo2"){
bat """
git add $files2push
git commit -m "commit msg"
git push
"""
}
}
How to handle merge conflict case, common files in repo2 could be edited by someone else when jenkins tries to merge.如何处理合并冲突情况,当 jenkins 尝试合并时,repo2 中的常用文件可能被其他人编辑。 What I'm thinking is to log the merge conflict and let the user handle it by fixing the merge conflict and retriggering the jenkins job.
我在想的是记录合并冲突并让用户通过修复合并冲突并重新触发 jenkins 作业来处理它。
is there a better way to achieve this?
有没有更好的方法来实现这一目标?
Yes.是的。 Git subtree
Git 子树
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.