This project is to set up a Jenkins instance in docker, whose configuration is
defined as code(casc.yaml
), and jobs are generated by code(seedjob.groovy
).
It's difficult to trace the change in Web UI, so if different operators make changes, many problems may escape detection. Everything-as-code ensure all components can be set up from scratch in a relatively short period of time and its changes can be traced by SCM, such as Bitbucket.
The goal is everything-as-code. If we follow this strategy, it only takes a few minutes for both a new team member and experienced engineers to set up a new Jenkins instance locally which is exactly the same as that in production environment.
Everythong-as-code that enables someone who has knowledge of Jenkins and a platform to run a Jenkins instance so that someone else who has neither extensive knowledge of Jenkins or the way it needs to be run on the platform can use it.
-
Clone this project
git clone https://github.com/zhan9san/Jenkins-in-Docker.git
-
Add a file
jks.env
like below, replace the values with yours.cd Jenkins-in-Docker cat << EOF > jks.env JENKINS_ADMIN_ID=admin JENKINS_ADMIN_PASSWORD=OVER_WRITE_ME JENKINS_DOMAIN=OVER_WRITE_ME EOF
JENKINS_ADMIN_ID
is the Jenkins admin usernameJENKINS_ADMIN_PASSWORD
is the Jenkins admin passwordJENKINS_DOMAIN
is the domain of Jenkins. It can be the IP of your laptop, such as192.168.1.2
. Once set, the Jenkins URL would behttp://192.168.1.2:8080
.
-
Build Jenkins image
docker compose build
-
Run Jenkins
docker compose up -d
-
Access Jenkins
http://<JENKINS_DOMAIN>:<JENKINS_HTTP_PORT>
docker compose logs -f
docker compose down
Refer to kubernetes-plugin
Ensure the token and cert of servive account jenkins
are set correctly.
kubectl get secret $(kubectl get sa jenkins -o yaml | yq e '.secrets[0].name' -) -o yaml | yq e '.data.token' - | base64 -d
kubectl get secret $(kubectl get sa jenkins -o yaml | yq e '.secrets[0].name' -) -o yaml | yq e '.data."ca.crt"' - | base64 -d
There are two options to change these two configurations.
-
Web UI.
Manage Jenkins
->Manage credentials
->jenkins-token-kubernetes
->Update
->Secret(Change password)
.Manage Jenkins
->Manage Nodes and Clouds
->Configure Clouds
->Kubernetes Cloud details
->Kubernetes server certificate key
-
casc
. Update thecasc.yaml
(Recomended)credentials
->system
->domainCredentials
->credentials
->string
->secret
jenkins
->clouds
->kubernetes
->serverCertificate
- Reload configuration