vmware-templatesjenkins

Use Git with Jenkins

Jenkins runs as the jenkins 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 Jenkins user.

Configure the jenkins User to Access the Git Repository

  • Copy the private key to access to the repository into the /home/jenkins/.ssh folder:

    $ sudo cp /path/to/id_rsa /home/jenkins/.ssh/
    
  • Change the permissions

    $ sudo chown -R jenkins:jenkins /home/jenkins
    
  • 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 jenkins
    $ /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.

Jenkins configuration

  • Create a new Job in Jenkins and specify the Git repository.

    Jenkins configuration

  • Run the build.

If everything was properly configured, Jenkins will checkout the code from the Git repository.

Last modification September 4, 2018