Jenkins Bitbucket LFS-pull failing with missing protocol 'unknown'

Viewed 154

I'm trying to set up a Bitbucket-Repo for building in Jenkins. However, whenever there is a LFS-file in the Repo, the pull fails with the error "missing protocol 'unknown'".

This happens both with the "Add Git LFS pull after checkout."-Behaviour as well as when adding a 'git lfs pull' to my pipeline. "git lfs env" further shows that the endpoint is empty (even after the normal checkout)

Is there a setup-step that I a missing?

1 Answers

In jenkinsci/bitbucket-branch-source-plugin issue 593, the OP (actually the same Frank v Hoof ;) reports the following workaround:

I finally managed to do a workaround for it.

  • I added a 'normal' set of credentials (username & App-password) to Jenkins.
  • Then, when pulling (checkout scm), I skip LFS.
  • Afterwards I set the lfs-url to the one using the Username & App-Password, then do a LFS pull with those:
sh 'git lfs install --skip-smudge' // Required because LFS is currently failing
script {
    def scmVars = checkout scm
    // Workaround for LFS: Manually set the LFS-URL using Username & App Password, then do a pull using those instead of the OAuth
    // Remove everything up to @bitbucket.org from the Git URL (strip out the Bitbucket OAuth-credentials)
    echo "Performing LFS-Workaround to fix issue with LFS not working when using OAuth-credentials"
    def partialURL = sh(returnStdout: true, script: """echo $scmVars.GIT_URL | sed -e 's/https:\\/\\/.*:.*@bitbucket.org//'""")
    partialURL = partialURL.replace('\0', '').replace('\n', '') // Remove Null-Char & End-Line
    withCredentials([usernamePassword(credentialsId: 'Bitbucket_Basic', passwordVariable: 'BB_APP_PASS', usernameVariable: 'BB_USER')]) {
        // Generate new LFS-URL using Username & App-Password
        def LFSUrl = 'https://$BB_USER:$BB_APP_PASS@bitbucket.org' + partialURL + '/info/lfs'
        sh "git config lfs.url ${LFSUrl}" // Set as LFS-URL for the pull
        sh 'git lfs pull' // Pull LFS-files using workaround-config
    }
}

You have other LFS exclusion options, but --skip-smudge is enough in this case.

Related