Configure Jenkins

In this lab exercise, you configure your Jenkins instance to pull from GitHub, build a new Docker image with any code changes, push the Docker image to DockerHub, and deploy your application.

Step 1

Navigate to your Jenkins UI

From your DC/OS Services tab, hover your mouse over the Jenkins icon and click the open in new window icon.

jenkins-open

Step 2

Add DockerHub credentials

From your Jenkins UI, select Credentials, then select System. Click Global credentials.

In the left navigation pane, select Add Credentials.

jenkins-add-credentials

Add in your personal DockerHub credentials:

  • Username: your personal DockerHub username (not email!)
  • Password: your personal DockerHub password
  • ID: DockerHub

When complete, click OK.

jenkins-add-dockerhub-creds

Step 3

Add GitHub credentials

In the left navigation pane, select Add Credentials.

Add in your personal GitHub credentials:

  • Username: your personal GitHub username (not email!)
  • Password: your personal GitHub password
  • ID: GitHub

When complete, click OK.

jenkins-add-github-creds

Step 4

Create your Jenkins pipeline

Return to the Jenkins home screen by clicking the Jenkins logo in the top navigation bar.

jenkins-home

Next, select Create new jobs from the Jenkins home screen.

jenkins-create-new

Name your project anything you want (lowercase only, no spaces). Select Freestyle project and click OK at the bottom of the screen.

jenkins-create-pipeline

Now, you need to point Jenkins to the GitHub repository you forked in Lab 1.

Scroll down to the Source Code Management section of the page, and select Git.

jenkins-select-git

In the Repository URL field, add the URL to your GitHub repository. You can find the URL to your repository by navigating to the repository on GitHub, selecting Clone or Download and copying the link, as shown.

jenkins-find-github-url

Returning to Jenikns, paste your GitHub repository URL.

In the credentials selector, choose your GitHub credentials (which you provided to Jenkins in Step 3 above).

jenkins-git-credentials

Scroll down the page to the Build section.

Select Add build step and choose Docker Build and Push from the dropdown.

Add in the following information:

  • Repository name: <your personal DockerHub username (not email!)>/cicd-demo
  • Tag: $GIT_COMMIT
  • Registry credentials: Select the DockerHub credentials you created in Step 2 above.

jenkins-docker-credentials

Scroll down the page once more to the Post-build Actions section, and select Add post-build action.

From within the drop-down menu, select Marathon Deployment and click Advanced.

jenkins-post-build-click-advanced

Add in the following information:

  • Marathon URL: http://leader.mesos:8080
  • Definition file: conf/cd-demo-app.json
  • Docker Image: <your personal DockerHub username (not email!)>/cicd-demo:$GIT_COMMIT

When complete, click Save.

jenkins-post-build-config

Congratulations! Your Jenkins build pipeline is now configured and ready to use!