Jenkins GitLab Community Edition Integration Error - jenkins

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.

Related

gitlab oauth2 authentication in 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?

Jenkins build job giving error - java.net.BindException: Address already in use: JVM_Bind

I am trying to build simple Jenkins build job in my local workspace. I have built simple mvc gradle application. Jenkins build job has been setup with required gradel task but getting below error for jmx
Running as SYSTEM
Building in workspace C:\Users\harshal\.jenkins\workspace\MVCApp
The recommended git tool is: NONE
No credentials specified
> git.exe rev-parse --resolve-git-dir C:\Users\harshal\.jenkins\workspace\MVCApp\.git # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://github.com/harshalpatil2012/HelloWorld-MVC-App.git # timeout=10
Fetching upstream changes from https://github.com/harshalpatil2012/HelloWorld-MVC-App.git
> git.exe --version # timeout=10
> git --version # 'git version 2.9.0.windows.1'
> git.exe fetch --tags --progress -- https://github.com/harshalpatil2012/HelloWorld-MVC-App.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
Checking out Revision a7cf612bd16cc92d5e56137284de5318ce9beec2 (refs/remotes/origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f a7cf612bd16cc92d5e56137284de5318ce9beec2 # timeout=10
Commit message: "spring gradle demo app"
> git.exe rev-list --no-walk a7cf612bd16cc92d5e56137284de5318ce9beec2 # timeout=10
[MVCApp] $ C:\Windows\system32\cmd.exe -xe C:\Softwares\apache-tomcat-8.5.75\temp\jenkins5788250459304119055.sh
Microsoft Windows [Version 10.0.18363.1556]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\harshal\.jenkins\workspace\MVCApp>[Gradle] - Launching build.
[MVCApp] $ cmd.exe /C "C:\Users\harshal\.jenkins\workspace\MVCApp\gradlew.bat clean build && exit %%ERRORLEVEL%%"
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1099; nested exception is:
java.net.BindException: Address already in use: JVM_Bind
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
I have disabled jmx as below but still not sure why I am gettign same error in build execution.
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
I have deployed JENKINS war in my local tomcat 8.5 using intellj
The error is telling you that there is some service or process using port 1099. You need to find what process is using that port, then kill/end it (or change the port gradle is using) and rerun your job. I'm not a Windows user but the same principle should follow: Using NetStat.exe you can see the used ports in your machine with their processes. Also this answer can also help you.
This issue was due to the Intellj trying to connect to JMX during startup. I switched to eclipse and Jenins setup was working correctly via my eclipse tomcat server deployment.

Unable to clone Bit Bucket repository using Jenkins Job

I have created a Jenkins' job to clone, build and deploy the code on tomcat server. But every time I run the job it ends exactly after 10 mins with same error
10:57:59 ERROR: Error cloning remote repo 'origin'
10:57:59 [DeployPublisher][INFO] Build failed, project not deployed
10:57:59 Finished: FAILURE
I know the root cause which is timeout is set to 10 min by default while jenkins job triggers the clone command
10:47:57 > git.exe --version # timeout=10
10:47:58 > git.exe fetch --tags --force --progress -- repository-url +refs/heads/*:refs/remotes/origin/* # timeout=10
10:57:58 ERROR: Timeout after 10 minutes
10:57:59 ERROR: Error cloning remote repo 'origin'
What I couldn't figure out is how to increase this default timeout.
Followings are the list of Git plugins that I have been using
Plugins used
Any help would be appreciated. Thanks in Advance
I have looked into Jenkins documentation and found few Keywords and searching with them, ends up to the answer of my question.
Please refer to this for answer

Jenkins Service Account failing to pull from Git

I am having some trouble that randomly started with Jenkins. All of our jobs have begin to fail and it looks like there is a credential issue with the service account we use to run our jobs. This randomly started. I have tried updating the version of Jenkins and the plugins, but there is no change. Here is the output we receive on any job that runs:
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://site.visualstudio.com/_git/prodscripts # timeout=10
Fetching upstream changes from https://site.visualstudio.com/_git/prodscripts
> git.exe --version # timeout=10
using GIT_ASKPASS to set credentials site git repo
> git.exe fetch --tags --progress https://site.visualstudio.com/_git/prodscripts +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://site.visualstudio.com/_git/prodscripts
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:888)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1155)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
at hudson.scm.SCM.checkout(SCM.java:504)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
at hudson.model.Run.execute(Run.java:1810)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Caused by: hudson.plugins.git.GitException: Command "git.exe fetch --tags --progress https://site.visualstudio.com/_git/prodscripts +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Logon failed, use ctrl+c to cancel basic credential prompt.
fatal: Authentication failed for 'https://site.visualstudio.com/_git/prodscripts/'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2016)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1735)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:420)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:886)
... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
I have also confirmed that the service account can login to our git repository with no issue and confirmed the security permissions on there for the account. I am completely clueless on how Jenkins operates and have inherited Jenkins from someone else, so I'm having a really tough time trying to figure out the problem. Any help would be greatly appreciated.
Edit: I would also like to add that when I try to look at the job configurations, I receive this:
Well, I don't know what happened, but it looks like it seemed to fix itself. After updating Jenkins, it's plugins and Git on the master, the next morning we update the service account creds and that didn't work. Then we tried to use the alternative credentials found in Azure DevOps. Right after adding them in, we went to a job to change the credentials, but we did not receive the error from the picture above with the service account creds selected. We ran the job with the original creds and it ran without issue.
Please make sure you are using the right credentials and if it has changed recently, don't forget to update it in Jenkins credential manager. I was facing a similar issue but when I updated the password - it resolved.

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?

Resources