11

I have an issue with git LFS use in Jenkins. What I am doing now is that

  1. I am building a war from maven through Jenkins that war contains a jar file
  2. 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.

We have used git plugin and git-client plugin with version 3.3.0 and 2.4.2 respectively in Jenkins.

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)

so my questions are:

  1. how to use git LFS in the Jenkins?
  2. is there any separate Git Lfs plugin for Jenkins?
  3. How should the file convert to its original size during checkout when one use Git LfS?
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
Sidharth Rath
  • 159
  • 1
  • 1
  • 11
  • At a glance, the docs are not great, and I don't have Jenkins on hand, so I can't *fully* answer. However, I can say this: you shouldn't need a separate plug-in as the git plug-in has LFS support since 3.1.0 You might find some help from this issue log: https://issues.jenkins-ci.org/browse/JENKINS-35687 – Mark Adelsberger Jul 05 '17 at 13:42

2 Answers2

24

This can be done using the regular Git+Plugin for Jenkins (version 3.1.0 onwards).

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:

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

030
  • 10,842
  • 12
  • 78
  • 123
Andy Smith
  • 341
  • 1
  • 4
  • Thanks... This worked; hate having my git repo hard coded though. We're using organizations in github and I was hoping I could set everything from there; shame it has support for "git lfs pull" after checkout - but doesn't seem to actually work. God damn, I hate Jenkins. Can't wait to move off this shit. – TJ Biddle Jun 11 '18 at 21:54
  • 2
    Gave me this: "hudson.plugins.git.GitException: Command "git lfs pull origin" returned status code 1: stdout: stderr: git: 'lfs' is not a git command. See 'git --help'. Did you mean this? log ". This might need git lfs pre installed on the slave... – Prathamesh dhanawade Aug 08 '19 at 18:22
15

This can be done with "Pre SCM BuildStep” Plugin.

  1. Add “Pre SCM BuildStep” Plugin in Jenkins.

  2. In Job Configuration

    1. Select the property Run buildstep before SCM runs in Build Environment Section

    2. Click on Add Build Step

    3. Select Execute Shell or Execute Windows batch command.

    4. Add the following command in the shell,

      git lfs install

  3. In the Source Code Management section -> Additional Behaviours -> Add Git LFS pull after checkout.

Reference Link

John Rocha
  • 1,656
  • 3
  • 19
  • 30
Priya Talreja
  • 560
  • 6
  • 10