Use Git with Jenkins

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

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 ' (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

  • Run the build.

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

Last modification October 3, 2019