gitlab oauth2 authentication in jenkins - jenkins

I have configured a jenkins test job just to clone a git repo and provided the "Repository URL" like below
https://oauth2:glpat-Vn4Vgvft7-2W4P1m4b4Z#gitlab.com/test/batch/test.git
but while running the job I am getting the console error output as below
Cloning the remote Git repository
Cloning repository https://oauth2:glpat-Vn4Vgvft7-2W4P1m4b4Z#gitlab.com/test/batch/test.git
> git init /jenkins/jobs/test/workspace # timeout=10
Fetching upstream changes from https://oauth2#gitlab.com/test/batch/test.git
> git --version # timeout=10
Setting http proxy: 10.203.195.26:8080
> git fetch --tags --progress https://oauth2#gitlab.com/test/batch/test.git
+refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
The question is, while it is cloning it is showing the URL as https://oauth2:pass#gitlab.com
but why the password is not coming while fetching?

Related

Jenkins GitLab Community Edition Integration Error

I'm trying to integrate Jenkins (ver. 2.337) for our project on our gitlab.doman.com (GitLab Community Version 13.0.3), and it is deployed and running on Linux Centos on AWS EC2.
When I try to test using my GitLab Access Token, it gives me error stating Connection Timed Out.
When I try with Gitlab webhooks and SSH Key as credentials instead of Access Token, webhooks execute successfully, but the job on jenkins fails with the below errors.
I am quite new to Jenkins, and CI/CD. So, any guidance or help resolving this issue is greatly appreciated!
Jenkins Console Log:
Started by GitLab push by j****
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/xx_xxxxx
The recommended git tool is: NONE
using credential 7c284997-927a-40d9-b1cf-02axxxxxxxxx
> /usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/xx_xxxxx/.git # timeout=10
Fetching changes from the remote Git repository
> /usr/bin/git config remote.origin.url git#gitlab.sampledomain.co.kr:xx_xxxxxDetection/xx_xxxxx_detection.git # timeout=10
Fetching upstream changes from git#gitlab.sampledomain.co.kr:xx_xxxxxDetection/xx_xxxxx_detection.git
> /usr/bin/git --version # timeout=10
> git --version # 'git version 1.8.3.1'
using GIT_SSH to set credentials GitLab_SSH_Key
> /usr/bin/git fetch --tags --progress git#gitlab.sampledomain.co.kr:xx_xxxxxDetection/xx_xxxxx_detection.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git#gitlab.sampledomain.co.kr:xx_xxxxxDetection/xx_xxxxx_detection.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
at hudson.scm.SCM.checkout(SCM.java:540)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1215)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:645)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:517)
at hudson.model.Run.execute(Run.java:1896)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress git#gitlab.sampledomain.co.kr:xx_xxxxxDetection/xx_xxxxx_detection.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: ssh: connect to host gitlab.sampledomain.co.kr port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:618)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
A GitLab Access Token would work only for HTTPS URL (replacing your GitLab account password)
If you see Connection timed out both for HTTPS URL and SSH URL (git#gitlab.sampledomain.co.kr:... as in your question), it means gitlab.sampledomain.co.kr is not reachable from the Jenkins controller server which tries to contact your Git repository hosting server.
You need to make sure such a server can do a simple curl -v telnet://gitlab.sampledomain.co.kr:22 or curl -v telnet://gitlab.sampledomain.co.kr:443, before being able to run a service like Jenkins.

GIT_SSH not working on one of my windows slaves

Super frustrating because this is working on one of my windows slaves, but not this one- and I cant find any config differences.
On the working slave I see this:
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository git#bitbucket.org:myteam/myapp.git
> git init C:\Jenkins\workspace\test-slave123456 # timeout=10
Fetching upstream changes from git#bitbucket.org:myteam/myapp.git
> git --version # timeout=10
using GIT_SSH to set credentials mygitcreds
> git fetch --tags --progress git#bitbucket.org:myteam/myapp.git +refs/heads/*:refs/remotes/origin/* # timeout=45
> git config remote.origin.url git#bitbucket.org:myteam/myapp.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url git#bitbucket.org:myteam/myapp.git # timeout=10
Fetching upstream changes from git#bitbucket.org:myteam/myapp.git
using GIT_SSH to set credentials mygitcreds
> git fetch --tags --progress git#bitbucket.org:myteam/myapp.git +refs/heads/*:refs/remotes/origin/* # timeout=45
> git rev-parse "origin/test-slave^{commit}" # timeout=10
Checking out Revision 30f11ef09ab13f73fb9a6b75983e1bf32437f51d (origin/test-slave)
Enabling Git LFS pull
> git config core.sparsecheckout # timeout=10
> git checkout -f 30f11ef09ab13f73fb9a6b75983e1bf32437f51d # timeout=45
> git config --get remote.origin.url # timeout=10
using GIT_SSH to set credentials mygitcreds
> git lfs pull origin # timeout=45
Commit message: "test slave"
> git rev-list --no-walk 30f11ef09ab13f73fb9a6b75983e1bf32437f51d # timeout=10
But on the failing slave:
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository git#bitbucket.org:myteam/myapp.git
> git init C:\Jenkins\workspace\test-slave123456 # timeout=10
Fetching upstream changes from git#bitbucket.org:myteam/myapp.git
> git --version # timeout=10
using GIT_SSH to set credentials mygitcreds
> git fetch --tags --progress git#bitbucket.org:myteam/myapp.git +refs/heads/*:refs/remotes/origin/* # timeout=45
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress git#bitbucket.org:myteam/myapp.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: gituserfromcredbinding#bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Its the same pipeline job, same repo, same creds, and the slave should be configured the same but when I change the agent to point to the other slave it cant clone.
On the working slave all i had to do was install git for windows (turn off windows cred store), install java, and then run the jnlp jar.
Tried to do the same thing on the non working slave so I dont know why that one could be failing.
Bitbucket is not able to authenticate you on the slave where it is not working.
Reason could be:
You have not setup the ssh key for the slave where it is not working
Or
The key which is there is not associated to the account you are
trying to use.
If creds etc everything is same, what you can try :
1.Copy the keys present inside the "known_hosts" file in the working slave.
2.Paste the keys copied in step 1 above into the "known_hosts" file of non-working slave.
If in case keys are also same in both the slaves try :
ssh into non-working slave and manually try to clone once. Reason being if you have never used that slave(non-working) earlier then it might ask for : "The authenticity of host, Are you sure you want to continue connecting (yes/no)" , for which you have to say Yes, only one time.
I change git bash from ver: 2.22.0 to ver:2.12.0 (and I select the 'Enable windows cred store'), the windows slave works again

Jenkins and git with custom port

I am trying to link a gitlab instance with a Jenkins instance. Due to being run in a DC/OS environment I cannot use the standard SSH port 22, so I am running gitlab on SSH port 16122 instead.
Gitlab displays SSH clone URLs in the format [git#git.company.de:16122]:user/test.git, which a normal git clone command understands. Also, Jenkins accepts this URI as SCM URI in the configuration screen (as evidenced by the error messages "invalid credentials" vanishing once I set the SSH key as credential that is configured as deploy-key in Gitlab.
The problem arises during actually building the job: jenkins for some unknown reason decides to double-urlencode the [ at the front of the URI and thus the build breaks:
Cloning repository %255bgit#git.company.de:16122]:user/test.git
> git init /var/jenkins_home/workspace/test # timeout=10
Fetching upstream changes from %25255bgit#git.company.de:16122]:user/test.git
> git --version # timeout=10
> git fetch --tags --progress %25255bgit#git.company.de:16122]:user/test.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress %25255bgit#git.company.de:16122]:user/test.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
When I look at the raw XML of the job using xxd on the shell, there are no "invisible" ASCII chars or similar in front of the repo URL.
What causes this, and is there a way to fix this without having to manually rewrite every URL to ssh://git#git.company.de:16122/user/test.git?

"Does not meet criteria" when using Jenkins multibranch pipeline

Anyone know why Jenkins multibranch pipeline would refuse to create build branches for my BitBucket repo? A Jenkins file exists in the root of the project, but it simply says "Does not meet criteria" with no real details:
Started by user Nick Smith
> git rev-parse --is-inside-work-tree # timeout=10
Setting origin to ssh://git#abcabc.com:7999/flex/flex-dataaggregation-service.git
> git config remote.origin.url ssh://git#abcabc.com:7999/flex/flex-dataaggregation-service.git # timeout=10
Fetching & pruning origin...
Fetching upstream changes from origin
> git --version # timeout=10
using GIT_SSH to set credentials myteam ssh key
> git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* --prune
Getting remote branches...
Seen branch in repository origin/bugfix/abc
Seen branch in repository origin/master
Seen 2 remote branches
Checking branch master
Does not meet criteria
Checking branch bugfix/abc
Does not meet criteria
Done.
Finished: SUCCESS
Thanks
Nick
Seems to fix itself! (see comment above)

jenkins job build not in slave node

build job( build docker image ,code from github) in slave machine by configuration,but it do not build success...if change job in master ,it build success
slave build message :
Started by user admin
Building remotely on jenkins-slave (slave) in workspace /home/jenkins/workspace/71bnh8co385ctlmoxgbumdnpnet3ywq
Cloning the remote Git repository
Cloning repository git#github.com:xxxxxxx/wcount.git
> git init /home/jenkins/workspace/71bnh8co385ctlmoxgbumdnpnet3ywq # timeout=10
Fetching upstream changes from git#github.com:xxxxxxx/wcount.git
> git --version # timeout=10
using GIT_SSH to set credentials 71bnh6gke9kmabye9qu2qsazzpofjsa
> git -c core.askpass=true fetch --tags --progress git#github.com:xxxxxxx/wcount.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url git#github.com:xxxxxxx/wcount.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url git#github.com:xxxxxxx/wcount.git # timeout=10
Fetching upstream changes from git#github.com:xxxxxxx/wcount.git
using GIT_SSH to set credentials 71bnh6gke9kmabye9qu2qsazzpofjsa
> git -c core.askpass=true fetch --tags --progress git#github.com:xxxxxxx/wcount.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse origin/master^{commit} # timeout=10
Checking out Revision 5730301886fa5c02522705de817c5ddac0f0dbce (origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 5730301886fa5c02522705de817c5ddac0f0dbce
> git rev-list 5730301886fa5c02522705de817c5ddac0f0dbce # timeout=10
ERROR: Build step failed with exception
java.lang.IllegalArgumentException: configured dockerFolder '/home/jenkins/workspace/71bnh8co385ctlmoxgbumdnpnet3ywq' does not exist.
at org.jenkinsci.plugins.dockerbuildstep.cmd.CreateImageCommand.execute(CreateImageCommand.java:93)
at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder.perform(DockerBuilder.java:75)
master workspace is /home/jenkins_home/workspace
slave workspace is /home/jenkins/workspace
i can find /home/jenkins/workspace/71bnh8co385ctlmoxgbumdnpnet3ywq directory in slave node。
i guess this build in master node,but i see the task in slave queue
jenkins docker-build-step plugin don't support task run on slave node,so you can change some code to support it 。
add a jar to slave which can create image and push image。then master invoke this jar in slave
Not sure if that's the case here, but it seems that Jenkins sets a path to Dockerfile in Docker build/create task at Build stage as $WORKSPACE/docker so you either have to ensure you have that folder (containing Dockerfile and other needed files) in your workspace/git repo or just remove docker from path ENV above (which is a better solution, imho) and Jenkins will read Dockerfile from main workspace/git directory. Hope that helps.

Resources