0
votes

I am trying to do a git clone of a private gitlab repo inside a shell script in Jenkinsfile and i have just been unable to find a way. I mean this is a simple git clone and i can't believe i have to come here to seek help with such simple task. It is unfortunate that gitlab support always comes with extra cost compared to github.

Another unfortunate thing is i have searched the whole internet and can't find a solution to my problem. I have the Gitlab plugin and also tried to use the gitlab api token, but there is no support for gitlab api token in jenkins..no way to use it with withcrdentials or any other thing

I have also tried regular withcredentials with username and password and that does not work either

also tried http and git repo url the http one says not found and the git or ssh one gives host key errors

what i have tried

   steps {
     git url: 'https://gitlab.example.com/user/example_repo.git', branch: 'master', credentialsId: 'my-gitlab-repo-creds'
   }

got this error

git: 'url:' is not a git command. See 'git --help'.

Did you mean this? prune

other errors from other trials and errors

Cloning into 'example_repo'... Host key verification failed. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

and

Cloning into 'example_repo'... fatal: could not read Username for 'https://gitlab.example.com': No such device or address

1

1 Answers

1
votes

I would recommend to use the checkout pipeline step instead of the git one.

            checkout([$class: 'GitSCM',
                branches: [[name: '*/master' ]],
                extensions: scm.extensions,
                userRemoteConfigs: [[
                    url: 'https://gitlab.example.com/user/example_repo.git',
                    credentialsId: 'my-gitlab-repo-creds'
                ]]
            ])

https://jenkins.io/doc/pipeline/steps/git/