Note: This is part 3 of the Jenkins docker tutorial series. Click here for part 1. And here for part 2.
You want to set up a Jenkins Docker service that automatically sets up the Jenkins settings so you don't have to do it manually.
TLDR: Bitbucket code here.
There is a Jenkins plugin called Jenkins Configuration as Code (JCasC) which provides the ability to define your whole Jenkins configuration as a YAML file. In this tutorial we will extend our initial Jenkins Docker service from previous posts to utilize the JCasC plugin such that it automatically sets up the configuration for
Following plugins must be installed:
In a previous tutorial, we learned how to create a Docker image that comes with default plugins pre-installed (we even installed exactly those 2 plugins).
The realization as code is threefold:
- We create a jenkins.yml file that contains our role-based config and the credentials for the admin user
- We set the environmental variable CASC_JENKINS_CONFIG to point to the location where we will place the jenkins.yml file from step 1
- We will bind-mount the jenkins.yml file into the location of CASC_JENKINS_CONFIG
We will create two global roles:
- an "admin" role with overall access-rights on the Jenkins server
- and a "readonly" role for all the other authenticated users, that is users that can log in.
For the first point, we need to use authorizationStrategy key, where we specify roleBased before we set up the global roles.
For the latter we populate the securityRealm key, define allowsSignup: false and set the username (id) and password of the admin user.