简体   繁体   English

Jenkins和Git稀疏结账

[英]Jenkins and Git sparse checkouts

I have a large repository in Git. 我在Git中有一个大型存储库。 How do I create a job in Jenkins that checks out just one sub-folder from the project? 如何在Jenkins中创建一个只从项目中检出一个子文件夹的作业?

Jenkins Git Plugin support sparse checkouts since git-plugin 2.1.0 (April, 2014). 自git-plugin 2.1.0(2014年4月)以来, Jenkins Git Plugin支持稀疏检出 You will need git >= 1.7.0 for this feature. 此功能需要git> = 1.7.0。 It is under "Additional Behaviors" -> "Sparse Checkout paths." 它位于“附加行为” - >“稀疏结账路径”下。

截图

See: Jira issue JENKINS-21809 见:Jira问题JENKINS-21809

You can use sparse checkout feature of Git. 您可以使用Git的稀疏结账功能。 Note that Git still clones whole repository to local disk. 请注意,Git仍然将整个存储库克隆到本地磁盘。 That's not too bad however, because it is compressed. 然而,这并不是太糟糕,因为它是压缩的。

  1. Create a new job in Jenkins, set Git repository in Source Code Management section. 在Jenkins中创建一个新作业,在源代码管理部分设置Git存储库。
  2. Build the project. 建立项目。 This will clone whole repository to local disk. 这会将整个存储库克隆到本地磁盘。
  3. Open projects's workspace folder, delete everything there except .git folder. 打开项目的工作区文件夹,删除除.git文件夹之外的所有内容。
  4. Open Git shell for project's workspace folder. 打开项目工作区文件夹的Git shell。 Enable sparse-checkout: 启用稀疏检查:

     git config core.sparsecheckout true 
  5. Update working tree: 更新工作树:

     git read-tree -mu HEAD 
  6. Create sparse-checkout file in .git/info folder. 在.git / info文件夹中创建sparse-checkout文件。 Add path to sub-folder you want to checkout to that file, like so (note trailing slash): 添加要签出到该文件的子文件夹的路径,如下所示(注意尾部斜杠):

     folder/to/include/ 
  7. Build the project again. 再次构建项目。 This time only one sub-folder should appear in workspace folder. 这次只有一个子文件夹应出现在工作区文件夹中。

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 . 要清除它,你可以只使用rm -rf工作文件夹并使用mkdir workingdir重新创建它。 This would require you to specify this option on the git level of the above command: 这将要求您在上述命令的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. 这一切都取决于你对詹金斯的了解程度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM