Skip to content

Instantly share code, notes, and snippets.

@ismet55555
Last active June 2, 2021 21:30
Show Gist options
  • Save ismet55555/15165dd053391a1b01db41cb8fdf3542 to your computer and use it in GitHub Desktop.
Save ismet55555/15165dd053391a1b01db41cb8fdf3542 to your computer and use it in GitHub Desktop.
Jenkins Server in Docker Container using Config as Code
  1. Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh && \
    sudo sh get-docker.sh && \
    rm get-docker.sh
  1. Download this gist zip file, unzip the file, and cd into its directory

  2. Build the Docker image

docker build -t jenkins:jcasc .
  1. Run the container
    • Note: Substitute credentials
docker run --name jenkins \
           --rm -p 8080:8080 \
           --env JENKINS_ADMIN_ID=admin \
           --env JENKINS_ADMIN_PASSWORD=password \
           jenkins:jcasc
  1. Navigate web browser to http://localhost:8080
##############################################################################
# Configuration as Code Jenkins Settings
#
# See more details here:
# - https://github.com/jenkinsci/configuration-as-code-plugin
#
##############################################################################
#
# NOTES:
# - Fine-grained user auth strategy: https://plugins.jenkins.io/matrix-auth/
# - More Jenkins user auth strategies:
# -https://www.jenkins.io/doc/developer/extensions/jenkins-core/#authorizationstrategy
#
##############################################################################
jenkins:
systemMessage: "This Jenkins server is running in Docker. Enjoy responsibly!\n\n"
numExecutors: 4
scmCheckoutRetryCount: 2
mode: NORMAL
securityRealm:
local: # Use basic user authentication
allowsSignup: false # Prevent anonymous users from creating an account through the web interface
users:
- id: ${JENKINS_ADMIN_ID}
password: ${JENKINS_ADMIN_PASSWORD}
authorizationStrategy:
globalMatrix: # Global server permissions
permissions:
- "Overall/Administer:admin" # Admin permissions to admin user
- "Overall/Read:authenticated" # All other authenticated users
remotingSecurity: # Control what things agent has access to and can do
enabled: true
unclassified:
location: # Jenkins URL path
url: http://server_ip:8080/
##############################################################################
#
# Commands:
# docker build -t jenkins:jcasc .
# docker run --name jenkins \
# --rm -p 8080:8080 \
# --env JENKINS_ADMIN_ID=admin \
# --env JENKINS_ADMIN_PASSWORD=password \
# jenkins:jcasc
#
##############################################################################
# Base image
FROM jenkins/jenkins:latest
LABEL name="Jenkins server"
LABEL contact="ismet.handzic@gmail.com"
# Environmental Variables
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
ENV CASC_JENKINS_CONFIG /var/jenkins_home/casc.yaml
# Installing Plugins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
# Get configuration as code file
COPY casc.yaml /var/jenkins_home/casc.yaml
ant:latest
antisamy-markup-formatter:latest
authorize-project:latest
build-timeout:latest
cloudbees-folder:latest
configuration-as-code:latest
credentials-binding:latest
email-ext:latest
git:latest
github-branch-source:latest
gradle:latest
ldap:latest
mailer:latest
matrix-auth:latest
pam-auth:latest
pipeline-github-lib:latest
pipeline-stage-view:latest
ssh-slaves:latest
timestamper:latest
workflow-aggregator:latest
ws-cleanup:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment