Jenkins DevKit: Windows Home
By: Joaquín Menchaca, 智裕
Tags: Continuous Integration, Windows 10, Jenkins, Docker, DevOps

Jenkins DevKit: Windows Home

Creating Jenkins DevKit on Windows 10 Home

Alright, I admit it, I have a gaming system that uses Windows 10 Home. Sometimes I would like to do some development things with Docker and Jenkins, but the system has been, well, challenging.

This article will show how you can create a local Jenkins DevKit environment using Docker and Jenkins on Windows 10 Home.

Background

Getting Docker

First, Docker Desktop cannot run on Windows 10 Home due to absent of Hyper-V. Microsoft would prefer that you purchase the more expensive Windows 10 Professional to gain access to Hyper-V. So you have to shop for a virtual machine alternative, and for me this is the open source Virtualbox.

What does this mean for Docker? There’s an alternative in the form of Docker Machine and Docker Compose that comes bundled with Docker Toolbox.

Getting Jenkins

You can bring up a quick and easy Jenkins build environment to build, test, and push docker images using Docker Compose. This requires the Jenkins build container to access the docker service.

Normally on macOS or Linux, you could mount the unix socket into the container, called docker-on-docker, but for Windows, this poses a little bit of a problem since Windows does not have unix sockets, given that Windows is, well, ahem, not Unix (or Linux).

We can use a TCP address instead, but the default behavior is to use encrypted TLS, but this won’t work for the docker client running inside the container.

So what do we do? We turn off the encryption and use insecure HTTP communication, which for ONLY your local development desktop, this should be fine.

Required Tools

You will need the following tools to for this solution

Virtualbox : this is an free open source solution that will allow you to run virtual machines on Windows 10 Home.

: this is an free open source solution that will allow you to run virtual machines on Windows 10 Home. Docker Toolbox : all the tools you will need to run Docker with Virtualbox on Windows 10 Home.

: all the tools you will need to run Docker with Virtualbox on Windows 10 Home. Chocolatey (optional): package manager that can facilitate downloading and installing packages on Windows.

Using Chocolatey (Optional)

If you have Chocolatey installed, you can get this tools with these commands:

choco install virtualbox

choco install docker-toolbox

Part A: Create Docker Environment

Step 1: Creating Virtual Machine

We need to create a virtual machine running Linux that will host the Docker Service.

docker-machine create --driver virtualbox default

Note, we are calling our system default , but you can use another name of your choosing.

Step 2: Reconfigure the Docker Service

Docker Machine does not have an option to run without TLS, so we have to reconfigure the service on the virtual machine.

First log into the virtual machine:

docker-machine ssh default

Inside the system, run these commands to edit the configuration and restart the Docker service:

sudo sed -Ei \

"s/(DOCKER_HOST='.*:)(.*)/\12375'/" \

/var/lib/boot2docker/profile

sudo sed -i \

"s/DOCKER_TLS=auto/DOCKER_TLS=no/" \

/var/lib/boot2docker/profile sudo /etc/init.d/docker restart

Exit out of the virtual machine with CTRL-D or by typing exit .

Step 3: Configure Docker Client

On any new PowerShell window, we must tell the docker CLI client to use the docker service we just setup, and without TLS:

$Env:DOCKER_TLS_VERIFY = ''

$Env:DOCKER_CERT_PATH = ''

$Env:DOCKER_HOST = "tcp://$(docker-machine ip):2375"

$Env:DOCKER_MACHINE_NAME = "default"

$Env:COMPOSE_CONVERT_WINDOWS_PATHS = "true"

Part B: Jenkins DevKit

Step 0: Create Project Structure and files

Run these PowerShell commands step by step below to create the directory and file structure for the project.

$project_path = "$home\projects\windevkit" # (1) equivalent of Linux `mkdir` command

New-Item -ItemType Directory -Force $project_path\jobdsl



# (2) equivalent of Linux `cd` command

Set-Location $project_path



# (3) equivalent of Linux `touch` command

@"

Dockerfile

docker-compose.yml

jenkins.yaml

jobs.yaml

plugins.txt

jobdsl\hello_flask.groovy

jobdsl\hello_sinatra.groovy

"@.Split([Environment]::NewLine) | `

ForEach-Object { New-Item -ItemType File -Name $_ }

Now that the structure is setup, we can download scripts used in this project that will setup and automate some basic configurations, as well as seed some jobs on Jenkins:

# Return to Project Directory

$project_path = "$home\projects\windevkit"

Set-Location $project_path # Variables used for downloading scripts

$GIST_PREFIX = "https://gist.githubusercontent.com/darkn3rd"

# Docker/Jenkins Automation

$GISTID_DOCKERFILE = "797e14b0a932250f87666a1aad6ea9ff"

$GISTID_PLUGIN_LST = "5da788f00466e2d5d1b3d619710fc647"

# Jenkins Configuration

$GISTID_JENKINSCFG = "99d580e70bd5f7a1859466eba1583422"

$GISTID_JOBSCONFIG = "892fa56401a47234e8f1fc07c65b8806"

# Jenkins Jobs

$GISTID_FLASKWEBMF = "176d33f682cbfb0ee391f286d8aebfd1"

$GISTID_SINATRA_WF = "f34517e8e6d9f0893ec90a902328946b"



# (1) download Jenkins plugins manifest

Invoke-RestMethod "$GIST_PREFIX/$GISTID_PLUGIN_LST/raw/" | `

Out-File -Encoding "ASCII" -FilePath plugins.txt # (2) download Dockerfile for Jenkins

Invoke-RestMethod "$GIST_PREFIX/$GISTID_DOCKERFILE/raw/" | `

Out-File -Encoding "ASCII" -FilePath Dockerfile



# (3) download Jenkins CaSC config

Invoke-RestMethod "$GIST_PREFIX/$GISTID_JENKINSCFG/raw/" | `

Out-File -Encoding "ASCII" -FilePath jenkins.yaml # (4) download Jenkins CasC config for JobDSL config

Invoke-RestMethod "$GIST_PREFIX/$GISTID_JOBSCONFIG/raw/" | `

Out-File -Encoding "ASCII" -FilePath jobs.yaml



# (5) download JobPipeline config for flask example

Invoke-RestMethod "$GIST_PREFIX/$GISTID_FLASKWEBMF/raw/" | `

Out-File -Encoding "ASCII" -FilePath jobdsl\hello_flask.groovy # (6) download JobPipeline config for flask example

Invoke-RestMethod "$GIST_PREFIX/$GISTID_SINATRA_WF/raw/" | `

Out-File -Encoding "ASCII" -FilePath jobdsl\hello_sinatra.groovy

Once these are completed successfully, the final file structure should look like this:

projects\

└── windevkit\

├── docker-compose.yml

├── Dockerfile

├── jenkins.yaml

├── jobdsl\

│ ├── hello_flask.groovy

│ └── hello_sinatra.groovy

├── jobs.yaml

└── plugins.txt

Step 1: Create Docker Compose file

Edit the Docker Compose script ( docker-compose.yml ) with the following contents:

docker-compose.yml

This script will setup a basic Jenkins DevKit that supports building images and running docker containers.

It is able to do this magic through the environment variable DOCKER_HOST , that points to the docker service running the virtual machine.

Step 2: Setup Docker CLI environment

As mentioned before, if we ran this in a new PowerShell window, we must setup the client:

Now you can use both the docker and docker-compose commands will work with the docker service running on the Linux virtual machine.

Step 3: Setup Docker Network

We need to setup a docker network to use with Jenkins DevKit. Run these commands in PowerShell:

We need to override the default behavior of Docker Compose, where docker network is automatically created.

For this solution to work, we’ll create the docker network first, then pass those settings to Docker Compose through the .env file, which will be used to configure the Jenkins container.

Step 3: Build Jenkins DevKit image

Build the Jenkins Devkit Docker image:

docker-compose build

Step 2: Run Jenkins DevKit Service

Now run the container:

docker-compose up

Part C: Interacting with Jenkins

The Jenkins server is seeded with two Jenkins Pipeline Jobs for demonstration purposes. We can use these to test that the solution works.

Logon onto Jenkins Service

To get started, we need to make note of the virtual machine IP address:

docker-machine ip

In your web browser of choice, type that IP followed by :8080 , so for example http://192.168.99.104:8008 .

In the prompt, use the user testuser and password of testuser .

Once logged on to the service, you should see something like this.

We’ll use the Blue Ocean UI for this, so click on the link in the left titled Open Blue Ocean, and in here we’ll see to jobs:

Step 2: Test a Python Flask Pipeline

On python, Flask is a popular microframework. We can run build the service and run some tests on it. Open the testjobs/hello-flask job and click run.

This will run through the build and test stages. Once finished, we can view the results by clicking on the Tests menu item at the top.

Step 3: Test a Ruby Sinatra Pipeline

On ruby, Sinatra is a popular microframework. We can run build the service and run some tests on it. Open the testjobs/hello-sinatra job and click run.

This will run through the requirements , build and test stages. Once finished, we can view the results by clicking on the Tests menu item at the top.

Related Articles

These are articles that delve into greater detail about automating different aspects of Jenkins and creating pipelines.

Jenkins Automation Articles

I wrote an article covering automating Jenkins configuration and plugin installation. [macOS and Linux]

I wrote an article covering automating Jenkins jobs and introduce Pipelines. [macOS and Linux]

Jenkins Pipeline and Building Unit Tests

This article demonstrates creating a small Flask server, creating unit tests, and then a small pipeline to run the unit tests.

This article demonstrates creating a small Sinatra server, creating unit tests, and then a small pipeline to run the unit tests.

Resources

These are some of the underlying automation with Jenkins used in this projects.

Jenkins Configuration as Code Plugin : use DSL in YAML to configure Jenkin server.

: use DSL in YAML to configure Jenkin server. Jenkins JobDSL Plugin : use Groovy DSL to configure Jenkins jobs.

: use Groovy DSL to configure Jenkins jobs. Jenkins Pipelines : define continuous integration using declarative or scripted Groovy

: define continuous integration using declarative or scripted Groovy Jenkins Docker Image: Jenkins services as a Docker container with automation support for installing plugins.

These are the Virtualbox and Docker related tools used in this project:

Docker Toolbox : collection of tools that allow you to use Linux docker containers on Windows.

: collection of tools that allow you to use Linux docker containers on Windows. Docker Machine : automates virtual machines to launch a Linux guest virtual machine used to run docker containers

: automates virtual machines to launch a Linux guest virtual machine used to run docker containers Docker Compose : declarative script to define operation of Docker containers as an alternative to Docker CLI or Docker web API

: declarative script to define operation of Docker containers as an alternative to Docker CLI or Docker web API Virtualbox: free open source solution for running virtual machines on Windows.

These are links to underlying web frameworks, test frameworks, and reporting standard used:

Ruby Sinatra web framework and Test::Unit test framework.

web framework and test framework. Python Flask web framework and UnitTest test framework

web framework and test framework JUnit XML reporting format used as standard for continuous integration platforms and test engines.

These are miscellaneous links related to this project:

PowerShell Scripting homepage

homepage Chocolatey package management solution that automates download and install popular packages on Windows.

Conclusion

The goal of all of this adventure was mainly to demonstrate how you can develop automation on Jenkins on Windows 10 Home. This also shows how to use Docker on Windows 10 Home.

You might have noticed some use of automation to setup Jenkins with pipelines and other configuration. For simplicity, I did not delve into that too much, as the focus was just getting such things to work on Windows.

If interested, visit the related articles for articles that focus on some of these automation topics in further detail with walk-throughs.