Checkout от Gitlab терпит неудачу в трубопроводе Jenkins - PullRequest
0 голосов
/ 17 мая 2019

Я прочитал много документации, но не смог решить эту проблему.

Я использовал приведенный ниже код для извлечения из gitlab в jenkinfile

checkout changelog: true, poll: true, scm: [
      $class: 'GitSCM',
      branches: [[name: "origin/${env.gitlabSourceBranch}"]],
      doGenerateSubmoduleConfigurations: false,
      extensions: [[
        $class: 'PreBuildMerge',
        options: [
          fastForwardMode: 'FF',
          mergeRemote: 'origin',
          mergeStrategy: 'default',
          mergeTarget: "${env.gitlabTargetBranch}"
        ]
      ]],
      submoduleCfg: [],
      userRemoteConfigs: [[
        credentialsId: 'gitlab-jenkins-user-credentials',  
        name: 'origin',
        url: "${env.gitlabSourceRepoHttpUrl}"
      ]]
    ]

Я даже пытался

checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab-jenkins-user-credentials', url: 'http://jenkins-master/testproject/devops_artifacts/test_devops.git']]]

Но я продолжаю получать эту ошибку:

    Warning: CredentialId "gitlab-jenkins-user-credentials" could not be found.
Cloning the remote Git repository
Cloning repository http://gitlab-master.com/testproject/devops_artifacts/test_devops.git
 > C:\Program Files\Git\cmd\git.exe init C:\jenkins-docker\workspace\wildfly_gitlab # timeout=10
Fetching upstream changes from http://gitlab-master.com/testproject/devops_artifacts/test_devops.git
 > C:\Program Files\Git\cmd\git.exe --version # timeout=10
 > C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress http://gitlab-master.com/testproject/devops_artifacts/test_devops.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress http://gitlab-master.com/testproject/devops_artifacts/test_devops.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Logon failed, use ctrl+c to cancel basic credential prompt.
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://gitlab-master.com/testproject/devops_artifacts/test_devops.git/'

Я установил webhook в этой форме

http://username:c4cc893d00cfc8865fc3@10.50.9.XXX:8080/project/wildfly_gitlab

И я проверил соединение, оно работает. Так же, как я настроил Gitlab в Jenkins

Jenkins configuration

И связь тоже работает. Я не знаю, почему я все еще получаю ошибку.

1 Ответ

0 голосов
/ 17 мая 2019

Похоже, вы используете учетную запись для GitLab, а не для git

credentialsId: 'gitlab-jenkins-user-credentials',  

Настройте токен доступа на GitLab и добавьте его в качестве учетных данных на Jenkins.Эти новые учетные данные должны использоваться для извлечения кода с помощью git.

Ссылка на this , чтобы увидеть, как использовать учетные данные GitLabConnection (отличные от учетных данных git), которые вы хотите использовать для построения MR.

Изссылка:

// Reference the GitLab connection name from your Jenkins Global configuration (http://JENKINS_URL/configure, GitLab section)
properties([gitLabConnection('your-gitlab-connection-name')])

node {
  checkout scm // Jenkins will clone the appropriate git branch, no env vars needed

  // Further build steps happen here
}
...