generaljenkins

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

  • Create the jenkins user folder:

      $ sudo mkdir /home/jenkins
      $ sudo mkdir /home/jenkins/.ssh
    
  • 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

  • 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:

    [![Jenkins configuration](/images/img/apps/jenkins/create-job-jenkins-3.png)](/images/img/apps/jenkins/create-job-jenkins-3.png)
    
  • Run the build.

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

Last modification December 21, 2022