Help Center> Elastic Cloud Server> Best Practices> Installing and Deploying Jenkins on an ECS
Updated on 2024-03-06 GMT+08:00

Installing and Deploying Jenkins on an ECS

Preparations

  • Before installing Jenkins, purchase an ECS (recommended configuration: 4 GB+ memory and 40 GB+ disk size) running CentOS 7.6. Bind an EIP to the ECS.
  • After the ECS is purchased, add the inbound rule listed in the following table to the security group to which the ECS belongs. For details, see Adding a Security Group Rule.

    Direction

    Type

    Protocol/Application

    Port/Range

    Source

    Inbound

    IPv4

    TCP

    8080

    0.0.0.0/0

Procedure

  1. Install JDK.

    To ensure compatibility with Jenkins, install JDK 11 (view supported Java versions).

    1. Remotely log in to the purchased ECS.
    2. Run the following command to view the current JDK version:

      java -version

      If JDK exists and its version is earlier than 11, uninstall the JDK.

      rpm -qa | grep java | xargs rpm -e --nodeps

    3. Install JDK 11.

      yum install -y java-11-openjdk

    4. Restart the ECS.
    5. Check whether the installation is successful.

      java -version

  2. Install Jenkins.

    1. Run the following commands one at a time:

      sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

      sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

      yum install -y jenkins --nogpgcheck

    2. Edit the Jenkins file.

      vim /etc/sysconfig/Jenkins

      #Port
      JENKINS_PORT="8080"
      #Modify the user
      $JENKINS_USER="root"
      #Modify directory permissions
      chown -R root:root /var/lib/jenkins
      chown -R root:root /var/cache/jenkins
      chown -R root:root /var/log/Jenkins
    3. Start Jenkins and check its status.

      systemctl start jenkins

      systemctl status jenkins

  3. Unlock Jenkins.

    1. In the address bar of your local browser, enter http:EIP bound to the ECS hosting Jenkins:8080. The unlocking page is displayed.

    2. Log in to the ECS.
    3. Obtain the activation password.

      cat /var/lib/jenkins/secrets/initialAdminPassword

    4. On the Unlock Jenkins page, paste this password into the Administrator password field and click Continue.
    5. Install suggested plugins. After the installation is complete, use the admin account to go to the next step.

    6. Save the settings and complete the installation. The Jenkins page is displayed.

Verification

Single Job

  1. Choose New item, select Freestyle Project, click OK.
  2. In Build Steps, select Execute shell, enter echo hello world; exit, and click OK.

  3. Click Build Now.
  4. Wait until the execution of build task in the lower left corner is complete. Click Console Output, you can see the job is finished and hello world is displayed.

Multiple Jobs

  1. On the plug-in management page, search for the MultiJob plug-in and install it.
    • After the plug-in is installed, you need to restart Jenkins for the plug-in to take effect. Select Download now and install after restart.

    • After Jenkins is restarted, check whether the MultiJob plug-in takes effect on the installed plug-ins page.

  2. Click New item, select MultiJob Project, and click OK.

    Before creating a MultiJob project, you need to create three jobs.

  3. In Build Steps, select MultiJob Phase.

  4. Add three jobs as follows.

  5. Save the settings. The jobs are added.
  6. Click Build Now. The three jobs are successfully built in sequence.