mex-docs

A Simple Jenkins Workflow

Prerequisites

Notes

  1. Although you can run Jenkins in a Docker container and configure it to allow Docker containers to be spawned inside the Docker container (ie, Docker in Docker), this is not really recommended. A better way is to spin up a VM and install Jenkins there.
  2. If you want to use webhooks to trigger builds, you will need to either have your Jenkins server exposed to the internet or you will need to port forward or tunnel out to receive the inbound hooks. One way to do this is via the ngrok utility.
  3. This document and the associated scripts are not intended for production use. They are very rough, and should be viewed as a POC.
  4. This document is not a step-by-step process, rather it is more high level and intended for someone with at least a passing knowledge of Docker and Jenkins.

Repositories

There are two key repositories we’ll be working with; these can be forked to your own github repo so you can edit them.

Jenkins Flow

  1. Code is edited in the hello-edge repository.
  2. The changes are committed and pushed to the hello-edge repository.
  3. A build is trigged by an inbound webhook from Git in the hello-edge repo.
  4. If that build is successful, it is pushed to the MobiledgeX Docker Repository.
  5. A trigger fires on completion of the workflow and causes a build to be started in the jenks-test repository.
  6. This build does the following:
    1. Logs in using storged credentials from Jenkins.
    2. Generates a JWT.
    3. Checks for running AppInst, App, and ClusterInst.
    4. Deletes the AppInst, App, and ClusterInst.
    5. Deploys an App.
    6. Deploys a ClusterInst.
    7. Deploys an AppInst.
  7. If the build fails at any point, the subsequent steps will error out with the exception of the Show/Delete steps which accept 400 errors.

Flow Notes

  1. Currently, 400 errors are allowed in the Show and Delete phases, which accounts for components already being deleted.

Setting up Jenkins

Setting up Credentials

Go to the “Credentials” screen in your Jenkins installation; this can be seen on the left hand side of the main screen. You will need to create two or three sets of credentials depending on how your Github account is configured (with our without 2FA).

  1. Your MeX credentials
  2. Your Github Login/Pass
  3. Your Login and a Github OAUTH Token (if you have 2FA enabled).

Create a Jenkins Pipeline for hello-edge

There are a few key configuration options that need to be set.

  1. The Github Project should be set to the URL of your repo.
  2. You need to indicate you are pulling the Jenkinsfile from SCM. This requires
    1. The URL of your repo.
    2. The selection of your credentials (plain text if you do not have 2FA enabled, with the OAUTH if you do)
    3. The filename will be Jenkinsfile
  3. You need to define how you want to trigger builds; you can do this manually, via a webhook (provided you meet the requirements), or a simple poll of the SCM.
  4. Be sure to update the Jenkinsfile to match your requirements in terms of repos, naming, etc.

You can begin the configuration process by selecting “New Item” on the lefthand menu bar, then providing a name and clicking on the “Pipeline” option. Note that the name does not have to be the same as the repository.

These images here and here show a configuration that uses webhooks.

Run the Build

Click on the “Build Now” button for your project, even if you have setup webhooks, as our first concern is to make sure the image builds.

You can watch the build from the screen for the pipeline you are running. If there is a failure, you can use the tools on the left side to debug the issue. The “Console Output” option is usually the easiest way to debug.

Create a Jenkins Pipeline for jenks-test

The jenks-test repo contains the necessary logic to deploy the docker image you have built to the edge. Once again, please take the time to clone the repo and update your variables to match your particular needs.

The configuration options that need to be set for this pipeline are as followed.

  1. The Github Project should be set to the URL of your repo.
  2. You need to indicate you are pulling the Jenkinsfile from SCM. This requires
    1. The URL of your repo.
    2. The selection of your credentials (plain text if you do not have 2FA enabled, with the OAUTH if you do)
    3. The filename will be Jenkinsfile
  3. This build will be configured to only execute following a successful build of the Docker container.
  4. Be sure to update the Jenkinsfile to match your requirements in terms of repos, naming, etc.

As before, you can begin the configuration process by selecting “New Item” on the lefthand menu bar, then providing a name and clicking on the “Pipeline” option.

Here is an example screen shot; note that in this case the project name does not match the github project name.

FAQ