Introduction to Jenkins

In this section of the guide, we look at Jenkins. Jenkins is an important tool when enabling continuous integration workflows. Jenkins is an open source continuous integration server that automates and integrates the build, test and merge of your development flow. You can configure Jenkins to fit the needs of your project. We will run Jenkins in a Docker container.

We install Jenkins in an Ubuntu 16.04 VM using the package manager titled Advanced Package Tool (apt). We will then examine:

  • How Jenkins usage applies to any Jenkins install implementation
  • How to use Jenkins Blue Ocean, a graphical tool that simplifies the continuous integration and delivery process

Install Jenkins on Docker

To install Jenkins with Docker for any OS, follow these steps:

  1. Start Jenkins in Docker by running the following command in a terminal/command prompt:

    docker run \
      -u root \
      --rm \  
      -d \ 
      -p 8080:8080 \ 
      -p 50000:50000 \ 
      -v jenkins-data:/var/jenkins_home \ 
      -v /var/run/docker.sock:/var/run/docker.sock \ 
      jenkinsci/blueocean

    For Windows, replace the ‘\’ characters with ‘^’ to enable multi-line command line inputs.

    Here is a brief explanation of each section of the command:

    docker run
    Run a specified image, that is noted later in the command, in a new container
    -u
    Run the container as the user root
    –rm
    For cleanliness, the container is automatically removed when it is shut down.
    -d
    Run the container in the background, in detached mode. If not specified, the Docker log for the container will output in the terminal window. Keeping the -d option helps keep this command tidy in a shell script, and keeps the launching terminal from being attached to the Jenkins instance.
    -p 8080:8080
    Map, or publish, the container port to a host port. The host port number is first, and the container port is second. Port 8080 is used to access Jenkins through a web browser. Port 50000 allows you to use other JNLP-based Jenkins agents on other machines. This functionality is not required for this example, but is good to know about if you are working with a master-slave system.
    -v jenkins-data:/var/jenkins_home
    Map host volumes to the container. This means that the container can use, store, and create data on the host. The first -v command is used to save Jenkins configuration data to the host machine, so that restarting Jenkins does not mean restarting all your work. The second -v /var/run/docker.sock:/var/run/docker.sock allows Jenkins to communicate with the Docker daemon on the host. This is required to run Docker containers through Jenkins, because Jenkins itself is a Docker container.
    jenkinsci/blueocean
    Run the Docker container with this name, which is the blue ocean image that is maintained by Jenkinsci. If this image is not already downloaded on your host machine, the docker run command will automatically download the image.
  2. Follow the Post-installation setup wizard:

    1. Navigate to this address in a web browser: localhost:8080
    2. Follow basic setup instructions. For first-time users, a special passcode is required which is stored in a local file. The Jenkins setup wizard will guide you through how to find and enter this passcode.
    3. Install recommended plug-ins.
    4. Create the first admin user with your selected username and password.

    Check that the Open Blue Ocean option is on the left side of the browser when on localhost:8080, because it should be pre-installed with the Docker image. If not, see step 3 of the steps in Install Jenkins on Linux for instructions on how to get the Blue Ocean plug-in.

Install Jenkins on Linux

If you prefer to install Jenkins directly on your Linux machine and not in a Docker container, follow these steps. On Linux, you can install Jenkins through the Advanced Package Tool (apt). This is useful if are not able to host Jenkins within a Docker container. As an extra requirement, however, you must have Java installed for Jenkins to install and work on Linux. Java is not required when installing through Docker.

Type java -version into your command-line. If Java is not installed, install it with the following terminal command:

sudo apt install openjdk-8-jre

To install Jenkins, follow these steps:

  1. Run these commands from a terminal:

    wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins

    Jenkins should automatically start and is accessible through a web browser at the address localhost:8080.

To complete the installation, additional steps are required:

  1. In a web browser, navigate to localhost:8080. Follow the basic setup instructions.

    Note: For first-time users only, a special pass code, which is stored in a local file, is required. The Jenkins setup wizard will guide you through how to find and enter this pass code.

  2. Install the recommended plug-ins.
  3. Create the first admin user with the username and password of your choice.
  4. Install the BlueOcean plug-in.
  5. Navigate to Manage Jenkins > Plugin Manager using the left navigation bars or go to the url localhost:8080/pluginManager.
  6. Navigate to the Available tab and type in Blue Ocean. Select the top option, and Jenkins will install dependencies automatically.
  7. Click Install without restart. After installation, refresh the page and navigate back to localhost:8080. You will see a new option. Open Blue Ocean in the left-hand menu, as you can see in the following screenshot:

     

Now that Jenkins is installed, we can create the first pipeline. Let’s look at this in Create pipeline.

Previous Next