jenkins git plugin: git environment variables are ignored in the checkout step

43 views Asked by At

It's seems impossible to pass environment to the git binary when using the jenkins checkout step https://www.jenkins.io/doc/pipeline/steps/params/scmgit/

This is necessary so I add enable tracing with git (e.g. using the GIT_CURL_VERBOSE environment variable https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables)

Here's my example pipeline to reproduce the problem:

pipeline {
    agent any
    environment {
        GIT_CURL_VERBOSE = true
    }
    stages {
        stage('Build') {
            steps {
                sh '''rm -rf git-dir
                '''
                dir('git-dir') {
                   checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/jenkinsci/git-plugin.git']])
                }
                sh '''printenv
                    ls -al
                '''
            }
        }
    }
}

In the clone using the checkout step, GIT_CURL_VERBOSE is ignored and nothing is printed. In the printenv output I see the environment is set though.

Is this a bug in the jenkins git plugin? Can I enable tracing anyway?

1

There are 1 answers

1
Frank Ammeter On

It seems you ran into this bug: https://issues.jenkins.io/browse/JENKINS-68580

You could invoke git directly as a workaround, if you replace the checkout step with this:

dir('git-dir') {
  sh '''rm -rf .git
  git init 
  git fetch --no-tags --force --progress -- https://github.com/jenkinsci/git-plugin.git +refs/heads/*:refs/remotes/origin/*
  '''
}

Tracing output will be available.