es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Jenkins se congela al hacer “git checkout” en las credenciales para LFS.

Tengo un Pipeline de varias ramas basado en un archivo de Jenkins que clona explícitamente otro repositorio proporcionado por parámetros. Veo que se congela y agota el tiempo después de intentar solicitar credenciales para git-lfs como parte del comando git checkout -f <HASH>.

¿Cómo puedo hacer checkout de un repositorio con acceso a git-lfs con credenciales?

Jenkinsfile:

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

Consola de Jenkins:
“`

<blockquote>
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'
utilizando GIT_ASKPASS para establecer credenciales para acceder a los recursos git
git fetch –tags –force –progress — <https_private_gitlab_url> +refs/heads/<em>:refs/remotes/origin/</em> # timeout=10
Evitar segunda búsqueda
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/<em>:refs/remotes/origin/</em> # timeout=10
git rev-parse refs/remotes/origin/master^{commit} # timeout=10
git config core.sparsecheckout # timeout=10
git checkout -f <hash> # timeout=10
Agota el tiempo
“`

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    Para hacer checkout de un repositorio con acceso a git lfs con credenciales, puedes agregar los siguientes pasos a tu Jenkinsfile antes del comando git checkout -f <hash>:

    steps{
      withCredentials([usernamePassword(credentialsId: 'git-lfs-creds', passwordVariable: 'GIT_LFS_PASSWORD', usernameVariable: 'GIT_LFS_USERNAME')]) {
        sh '''
          git lfs install
          git config credential.username $GIT_LFS_USERNAME
          git config credential.password $GIT_LFS_PASSWORD
          git config credential.helper "store --file=$HOME/.git-credentials"
          git lfs pull
        '''
      }  
      sh 'git checkout -f <hash>'
    }
    

    Esto instalará git lfs si aún no está instalado, configurará las credenciales para git lfs, descargarán los objetos LFS y finalmente hará checkout de la revisión requerida. Las variables de entorno GIT_LFS_USERNAME y GIT_LFS_PASSWORD se llenarán con las credenciales almacenadas en el ID de credenciales git-lfs-creds. Asegúrate de reemplazar git-lfs-creds con el ID real de tus credenciales de Git LFS en Jenkins.

Comments are closed.