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 $ /opt/bitnami/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
Before creating the first Job, it is necessary to configure the Git user and email that Jenkins will use to clone the repository. You can configure these options in the “Manage Jenkins -> Configure System -> Git plugin” section.
If everything was properly configured, Jenkins will checkout the code from the Git repository.