jenkins 中的 Git LFS 设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44927641/
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
Git LFS setup in jenkins
提问by Sidharth Rath
I have an issue with git LFS use in Jenkins. What I am doing now is that
我在 Jenkins 中使用 git LFS 有问题。我现在正在做的是
- I am building a war from maven through Jenkins that war contains a jar file
- through Git LFS we have converted that jar file into a pointer file. But during checkout from Jenkins that jar is not converting into its original size rather it is included in the war as a pointer.
- 我正在通过 Jenkins 从 Maven 构建War,该War包含一个 jar 文件
- 通过 Git LFS,我们已将该 jar 文件转换为指针文件。但是在从 Jenkins 结帐期间,该 jar 并没有转换为其原始大小,而是作为指针包含在War中。
We have used git plugin and git-client plugin with version 3.3.0 and 2.4.2 respectively in Jenkins.
我们在 Jenkins 中分别使用了 3.3.0 和 2.4.2 版本的 git 插件和 git-client 插件。
What is happening:
怎么了:
A.war -> a.jar(whose original size is 1234 kb but it's coming 3 kb (which is the size of pointer file)
A.war -> a.jar(原来的大小是 1234 kb,但现在是 3 kb(这是指针文件的大小)
so my questions are:
所以我的问题是:
- how to use git LFS in the Jenkins?
- is there any separate Git Lfs plugin for Jenkins?
- How should the file convert to its original size during checkout when one use Git LfS?
- 如何在 Jenkins 中使用 git LFS?
- Jenkins 有没有单独的 Git Lfs 插件?
- 当使用 Git LfS 时,文件应该如何在结帐期间转换为其原始大小?
回答by Andy Smith
This can be done using the regular Git+Pluginfor Jenkins (version 3.1.0 onwards).
这可以使用常规的Git+Pluginfor Jenkins(版本 3.1.0 以上)来完成。
If you are using Jenkins Pipelines (i.e. with a Jenkinsfile in the root of your repo), the key thing is to include the extension [$class: 'GitLFSPull']
in your checkout()
call. Here is an (edited) example taken from one of our repos:
如果您正在使用 Jenkins Pipelines(即在您的 repo 的根目录中有一个 Jenkinsfile),那么关键是[$class: 'GitLFSPull']
在您的checkout()
调用中包含扩展名。这是从我们的一个存储库中获取的(编辑过的)示例:
checkout([ $class: 'GitSCM',
branches: [[name: 'refs/heads/'+env.BRANCH_NAME]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'GitLFSPull'],
[$class: 'CheckoutOption', timeout: 20],
[$class: 'CloneOption',
depth: 0,
noTags: false,
reference: '/other/optional/local/reference/clone',
shallow: false,
timeout: 120]
],
submoduleCfg: [],
userRemoteConfigs: [
[credentialsId: 'foobar',
url: 'https://github.com/foo/bar.git']
]
])
Using the Snippet Generator it is possible to generate this code, by selecting "Git LFS pull after checkout" from the "Additional Behaviours" menu. See screenshot here
使用代码段生成器可以生成此代码,方法是从“其他行为”菜单中选择“结帐后提取 Git LFS”。在此处查看屏幕截图
回答by Priya Talreja
This can be done with "Pre SCM BuildStep” Plugin.
这可以通过“Pre SCM BuildStep”插件来完成。
- Add “Pre SCM BuildStep”Plugin in Jenkins.
- In Job Configuration, Select the property Run buildstep before SCM runsin Build Environment Section and Click on Add Build Step, Select Execute Shell. Add below command in the shell, git lfs install
- In the Source Code Management section -> Additional Behaviours -> Add Git LFS pull after checkout.
- 在 Jenkins 中添加“Pre SCM BuildStep”插件。
- 在 Job Configuration 中,在 Build Environment 部分中选择Run buildstep before SCM running属性,然后单击 Add Build Step,选择 Execute Shell。在shell中添加以下命令,git lfs install
- 在 Source Code Management 部分 -> Additional Behaviors -> Add Git LFS pull after checkout。