Search code examples
gitjenkinsgit-lfsjenkins-git-plugin

Jenkins git checkout freezing on credentials for LFS


I have a MultiBranch Pipeline based off a Jenkins file which explicitly clones another repository provided by parameters. I'm seeing that the it is freezing, and timing out, after attempting to ask for credentials for git-lfs as part of git checkout -f <HASH> command.

How can I checkout a repository with credentialed git lfs access?

Jenkinsfile:

stages {
    stage('Fetch Source Code') {
        steps{
            dir('repo') {
                git branch: "${params.Branch}", credentialsId: 'git-creds', url: "${params.RepoURL}"
            }
        }
    }

Jenkins console:

 > git init /home/jenkins/agent/workspace/<PIPELINE_NAME>/repo # timeout=10
Fetching upstream changes from <HTTPS_PRIVATE_GITLAB_URL>
 > git --version # timeout=10
 > git --version # 'git version 2.30.2'
using GIT_ASKPASS to set credentials Credentials to access git resources
 > git fetch --tags --force --progress -- <HTTPS_PRIVATE_GITLAB_URL> +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
Checking out Revision HASH (refs/remotes/origin/master)
 > git config remote.origin.url <HTTPS_PRIVATE_GITLAB_URL> # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f <HASH> # timeout=10
Times out 

Solution

  • After enough debug. I found out what was going on.

    By default the Git plugin won't provide credentials to most of the git commands (only fetch it appears), so when it does a checkout it freezes waiting for credentials to access LFS.

    By good design, though to my frustration, git/jenkins does not save the password anywhere on the machine and LFS objects are downloaded as part of the fetch. Setting up Jenkins to do LFS pull after checkout does not solve the issue as it is trying to do the LFS pull during the checkout.

    The solution is to set GIT_LFS_SKIP_SMUDGE=1 in the global environment variables and add the LFS pull to the checkout steps to explicitly pull in LFS objects.