How to do it...

Now let's install and configure Jenkins:

  1. Add the repository key to the system:
 wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
  1. Append the Debian package address to sources.list:
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
  1. Update the apt packages:
    sudo apt update
  1. Install Jenkins:
    sudo apt install jenkins
If you get an error when you install Jenkins, you can uninstall it with:

sudo apt-get remove --purge jenkins
  1. Start the Jenkins service:
    sudo systemctl start jenkins
  1. If you want to see the Jenkins status, use this command:
    sudo systemctl status jenkins

  1. Jenkins runs on port 8080 by default, and we need to open the Firewall to allow the traffic to that port:
    sudo ufw allow 8080
  1. If you want to verify the firewall status, do the following:
    sudo ufw status
If you see Status: inactive, you will need to run these commands to enable the firewall:

sudo ufw allow OpenSSH
sudo ufw enable

  1. It's time to run our Jenkins for the first time and configure it. For this, you need to visit http://<the_ip_or_domain_of_your_droplet>:8080. In my case, it's http://142.93.28.244:8080:

  1. To see the first password, you need to run:
    sudo cat /var/lib/jenkins/secrets/initialAdminPassword

  1. You will see the Welcome to Jenkins page. You have to select the "Install suggested plugins" option:

  1. You will see the installation process:

  1. Once the installation is complete, you need to create your first admin user:

  1. Confirm the Jenkins URL if you don't want to change it. Click Save and Finish:

  1. Jenkins is ready:

  1. The first view you will see in Jenkins is this one:

  1. Go to Manage Jenkins > Manage Plugins to install the GitHub plugin:

  1. Select the Available tab and then search for GitHub Integration. Now select the checkbox option and click on the Download now and install after restart button:

  1. Select the Restart Jenkins when installation is complete, and no jobs are running option:

  1. You will see this message:

  1. Wait one minute and then refresh the page. You may need to log in again.
  2. Go back to Manage Plugins; now you need to install the Post build task plugin.
  1. We can create our first Job by clicking on create new jobs on the homepage:

  1. Write the name of your job, select the Freestyle project option, and click on the OK button:

  1. In the General configuration, go to the Source Code Management section, select the Git option, and then write your GitHub project HTTPS URL (if you select your SSH URL, you will need to add new SSH keys for Jenkins in your GitHub):

  1. If your repository is private, you need to click on the Add button to specify your GitHub credentials (username and password):

  1. Select your credentials and make sure the master branch is selected as your main branch (it's recommended to use the master instead of others branches):

  1. Select the Post build task option on the Post-build Actions:

  1. In the textarea script, add npm install && npm run start-production. Click on Apply and then on the Save button:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset