Jenkins 和 Git 稀疏结帐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10791472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins and Git sparse checkouts
提问by Pavel Chuchuva
I have a large repository in Git. How do I create a job in Jenkins that checks out just one sub-folder from the project?
我在 Git 中有一个大型存储库。如何在 Jenkins 中创建一个仅从项目中检出一个子文件夹的作业?
回答by u?6??n? ???u?p
Jenkins Git Pluginsupport sparse checkoutssince git-plugin 2.1.0 (April, 2014). You will need git >= 1.7.0 for this feature. It is under "Additional Behaviors" -> "Sparse Checkout paths."
自 git-plugin 2.1.0(2014 年 4 月)以来,Jenkins Git 插件支持稀疏结帐。您将需要 git >= 1.7.0 才能使用此功能。它位于“其他行为”->“稀疏结账路径”下。
See: Jira issue JENKINS-21809
请参阅:Jira 问题JENKINS-21809
回答by Pavel Chuchuva
You can use sparse checkoutfeature of Git. Note that Git still clones whole repository to local disk. That's not too bad however, because it is compressed.
您可以使用Git 的稀疏结帐功能。请注意,Git 仍然会将整个存储库克隆到本地磁盘。然而,这还不算太糟糕,因为它被压缩了。
- Create a new job in Jenkins, set Git repository in Source Code Management section.
- Build the project. This will clone whole repository to local disk.
- Open projects's workspace folder, delete everything there except .git folder.
Open Git shell for project's workspace folder. Enable sparse-checkout:
git config core.sparsecheckout true
Update working tree:
git read-tree -mu HEAD
Create
sparse-checkout
file in .git/info folder. Add path to sub-folder you want to checkout to that file, like so (note trailing slash):folder/to/include/
Build the project again. This time only one sub-folder should appear in workspace folder.
- 在 Jenkins 中创建一个新作业,在 Source Code Management 部分设置 Git 存储库。
- 构建项目。这会将整个存储库克隆到本地磁盘。
- 打开项目的工作区文件夹,删除除 .git 文件夹之外的所有内容。
打开项目工作区文件夹的 Git shell。启用稀疏结帐:
git config core.sparsecheckout true
更新工作树:
git read-tree -mu HEAD
sparse-checkout
在 .git/info 文件夹中创建文件。将要签出到该文件的子文件夹的路径添加到该文件中,如下所示(注意尾部斜杠):folder/to/include/
再次构建项目。这次只有一个子文件夹应该出现在工作区文件夹中。
回答by Adam Dymitruk
You could have a custom step that would just use
你可以有一个只使用的自定义步骤
git checkout your-branch -- the/desired/path anthother/desired/path
To clear it you could just rm -rf
the working folder and recreate it with mkdir workingdir
. This would require you to specify this option on the git level of the above command:
要清除它,您可以只rm -rf
使用工作文件夹并使用mkdir workingdir
. 这将要求您在上述命令的 git 级别指定此选项:
git --working-dir="/path/to/workingdir" checkout your-branch -- the/desired/path anthother/desired/path
All this depends on how well you know Jenkins.
所有这一切都取决于您对詹金斯的了解程度。