Skip to content

Instantly share code, notes, and snippets.

@fhuitelec
Last active October 2, 2017 16:38
Show Gist options
  • Save fhuitelec/5b21fc3bd9eab394cae88bfee1945767 to your computer and use it in GitHub Desktop.
Save fhuitelec/5b21fc3bd9eab394cae88bfee1945767 to your computer and use it in GitHub Desktop.
Running a stateful Jenkins #evaneos #poc
# Build a clean Jenkins
docker build -f stateless.Dockerfile -t example/jenkins-example:stateless .
# Run it
docker run -d \
--privileged=true \
--name jenkins \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--publish 8080:8080 \
example/jenkins-example:stateless
# Do whatever you have to do:
# - install plugins
# - create your user
# - if you're using the default admin, be careful to change its password
# - add your build pipeline definition (example in the Jenkinsfile)
# Copy your jenkins_home from the running container
docker cp jenkins:/var/jenkins_home .
# Remove the useless container
docker rm -f jenkins
# Build a stateful Jenkins with your jenkins_home
docker build -f stateful.Dockerfile -t example/jenkins-example:stateful .
# Run your stateful Jenkins instance
docker run -d \
--privileged=true \
--name jenkins \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--publish 8080:8080 \
example/jenkins-example:stateful
# IT'S ALIVE!!
// Copy/paste it in the build pipeline you'll be creating
// Pipeline syntax: https://jenkins.io/doc/book/pipeline/syntax/
// Docker pipeline plugin docs: https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/index.html#docker-workflow
pipeline {
agent { docker 'php:7.1-alpine' }
stages {
stage('Build PHP 7.1') {
steps {
sh 'php -r \'echo "Hello World!";\''
}
}
}
}
FROM jenkins:alpine
USER root
RUN apk add --update git curl docker sudo
# cf. Jenkins docs : https://github.com/jenkinsci/docker#preinstalling-plugins
# cf. plugin docker: https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin
RUN /usr/local/bin/install-plugins.sh docker-workflow docker-plugin
ENV JENKINS_HOME /var/toto
COPY ./jenkins_home /var/toto
RUN chown -R jenkins:jenkins /var/toto
FROM jenkins:alpine
USER root
RUN apk add --update git curl docker sudo
# cf. Jenkins docs : https://github.com/jenkinsci/docker#preinstalling-plugins
# cf. plugin docker: https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin
RUN /usr/local/bin/install-plugins.sh docker-workflow docker-plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment