Use Git with Jenkins
Jenkins runs as the tomcat user so it is necessary to configure this user in case you want to access to a private repository. If you use a public repository, it is not necessary to configure the Tomcat user.
Configure the tomcat User to Access the Git Repository
Previous versions of Jenkins require creation of the tomcat user folder:
$ sudo mkdir /home/tomcat $ sudo mkdir /home/tomcat/.ssh
Copy the private key to access to the repository into the /home/tomcat/.ssh folder:
$ sudo cp /path/to/id_rsa /home/tomcat/.ssh/
Change the permissions
$ sudo chown -R tomcat:tomcat /home/tomcat
Save the hostname of your repository into the known_hosts file. Replace the YOUR_REPOSITORY placeholder with the URL to your Git repository.
$ sudo su tomcat $ installdir/git/bin/git ls-remote -h git@YOUR_REPOSITORY.git HEAD The authenticity of host 'ec2-xx-yy-zz.compute-1.amazonaws.com (xx.yy.zz)' can't be established. ECDSA key fingerprint is e5:xx:9d:yy:ff:89:55:47:aa:fd:b5:ee:0a:pp:6f:8d. Are you sure you want to continue connecting (yes/no)? yes
Configure the Git Repository in Jenkins
Create a new job in Jenkins by specifying the Git repository. To do so, navigate to the “Source Code Management” tab, select the “Git” option and enter the GitHub repository URL in the “Repository URL” field:
Run the build.
If everything was properly configured, Jenkins will checkout the code from the Git repository.