Jenkins on Docker
craigtrim@gmail.com
Extend
FROM jenkins
MAINTAINER Craig Trim "craigtrim@gmail.com"
ENV MAVEN_HOME /usr/lib/apache/maven/3.3.1
ENV PATH /usr/lib/apache/maven/3.3.1/bin:$PATH
USER root
RUN export DEBIAN_FRONTEND=noninteractive && 
apt-get update
RUN 
mkdir -p $MAVEN_HOME && 
cd $MAVEN_HOME && 
wget http://mirrors.ibiblio.org/apache/maven/maven-
3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz && 
tar -zxvf apache-maven-3.3.1-bin.tar.gz && 
mv apache-maven-3.3.1/* . && 
rm -rf apache-maven-3.3.1
USER jenkins
• Extend the official docker Jenkins file to
install Maven
• Official Image
• https://registry.hub.docker.com/_/jenkins/
• Extended Image
• https://github.com/torrances/docker/tree/master/jenkins
Build and Launch
• Build the docker image
• “craig/jenkins“
• Launch a container
• Expose on port 8040 (arbitrary)
• -p 8040:8080
• Inject a host directory
• This will contain all the Jenkins
customizations: build configurations,
credentials, workspace and built artifacts
• Around 130 MB immediately, and can
become very large over time
• -v ~/jpr:/var/jenkins_home
• Code is on the next page
• I like to use a shell script that handles any
host system manipulation and then calls
a docker-compose script
Docker (and docker-compose) installation script:
https://github.com/torrances/bash/blob/master/install/docker.sh
Build and Launch
docker-compose.yml
jenkins:
build: .
ports:
- "8040:8080"
volumes:
- ~/jpr:/var/jenkins_home
hostname:
jenkins
privileged:
false
run.sh
mkdir ~/jpr
sudo docker-compose up
View
• Pull up a web browser!
Further Configuration (creating new jobs):
http://trimc-devops.blogspot.com/p/masterpage.html#jenkins
Add Maven
Installation
• Click on Manage Jenkins
Add Maven
Installation
• Click on Configure System
Add Maven
Installation
• Scroll down
• Click the Add Maven button
• Unselect the Install automatically
checkbox
• In the Name textbox, put maven
• In the MAVEN_HOME textbox, enter the
path from the Dockerfile
(/usr/lib/apache/maven/3.3.1)
• Click Save
Maven Installation and Usage:
http://trimc-devops.blogspot.com/p/masterpage.html#maven
Install the Git Plugin
• Go back to the dashboard
• Select Manage Jenkins from the left-hand
nav
• Select Manage Plugins from the list
Install the Git Plugin
• Click on the Available tab
• Type github in the Filter text area
Install the Git Plugin
• Scroll down and select Github Plugin
• Click Install without restart
Install the Git Plugin
• Wait for the installation to complete
Install the Git Plugin
• Wait for the installation to complete
Install the Git Plugin
• Once the installation is complete, check
the Restart Jenkins when installation is
complete and no jobs are running
checkbox
Install the Git Plugin
• This will immediately restart Jenkins
Thanks!
Things that I haven’t got around to doing yet …
• Look into the use of a docker host to dynamically provision a slave,
run a single build, and tear down the host:
• https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin
• Install plugins (like Git) dynamically
• https://registry.hub.docker.com/_/jenkins/
• Do I need to install Maven on Docker first, or can this be installed
automatically when Jenkins initializes?

Jenkins on Docker

  • 1.
  • 2.
    Extend FROM jenkins MAINTAINER CraigTrim "craigtrim@gmail.com" ENV MAVEN_HOME /usr/lib/apache/maven/3.3.1 ENV PATH /usr/lib/apache/maven/3.3.1/bin:$PATH USER root RUN export DEBIAN_FRONTEND=noninteractive && apt-get update RUN mkdir -p $MAVEN_HOME && cd $MAVEN_HOME && wget http://mirrors.ibiblio.org/apache/maven/maven- 3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz && tar -zxvf apache-maven-3.3.1-bin.tar.gz && mv apache-maven-3.3.1/* . && rm -rf apache-maven-3.3.1 USER jenkins • Extend the official docker Jenkins file to install Maven • Official Image • https://registry.hub.docker.com/_/jenkins/ • Extended Image • https://github.com/torrances/docker/tree/master/jenkins
  • 3.
    Build and Launch •Build the docker image • “craig/jenkins“ • Launch a container • Expose on port 8040 (arbitrary) • -p 8040:8080 • Inject a host directory • This will contain all the Jenkins customizations: build configurations, credentials, workspace and built artifacts • Around 130 MB immediately, and can become very large over time • -v ~/jpr:/var/jenkins_home • Code is on the next page • I like to use a shell script that handles any host system manipulation and then calls a docker-compose script Docker (and docker-compose) installation script: https://github.com/torrances/bash/blob/master/install/docker.sh
  • 4.
    Build and Launch docker-compose.yml jenkins: build:. ports: - "8040:8080" volumes: - ~/jpr:/var/jenkins_home hostname: jenkins privileged: false run.sh mkdir ~/jpr sudo docker-compose up
  • 5.
    View • Pull upa web browser! Further Configuration (creating new jobs): http://trimc-devops.blogspot.com/p/masterpage.html#jenkins
  • 6.
  • 7.
  • 8.
    Add Maven Installation • Scrolldown • Click the Add Maven button • Unselect the Install automatically checkbox • In the Name textbox, put maven • In the MAVEN_HOME textbox, enter the path from the Dockerfile (/usr/lib/apache/maven/3.3.1) • Click Save Maven Installation and Usage: http://trimc-devops.blogspot.com/p/masterpage.html#maven
  • 9.
    Install the GitPlugin • Go back to the dashboard • Select Manage Jenkins from the left-hand nav • Select Manage Plugins from the list
  • 10.
    Install the GitPlugin • Click on the Available tab • Type github in the Filter text area
  • 11.
    Install the GitPlugin • Scroll down and select Github Plugin • Click Install without restart
  • 12.
    Install the GitPlugin • Wait for the installation to complete
  • 13.
    Install the GitPlugin • Wait for the installation to complete
  • 14.
    Install the GitPlugin • Once the installation is complete, check the Restart Jenkins when installation is complete and no jobs are running checkbox
  • 15.
    Install the GitPlugin • This will immediately restart Jenkins
  • 16.
  • 17.
    Things that Ihaven’t got around to doing yet … • Look into the use of a docker host to dynamically provision a slave, run a single build, and tear down the host: • https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin • Install plugins (like Git) dynamically • https://registry.hub.docker.com/_/jenkins/ • Do I need to install Maven on Docker first, or can this be installed automatically when Jenkins initializes?