Skip to content

zhan9san/Jenkins-in-Docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins-in-Docker

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.

How to set it up?

  1. Clone this project

    git clone https://github.com/zhan9san/Jenkins-in-Docker.git
  2. 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
    1. JENKINS_ADMIN_ID is the Jenkins admin username
    2. JENKINS_ADMIN_PASSWORD is the Jenkins admin password
    3. JENKINS_DOMAIN is the domain of Jenkins. It can be the IP of your laptop, such as 192.168.1.2. Once set, the Jenkins URL would be http://192.168.1.2:8080.
  3. Build Jenkins image

    docker compose build
  4. Run Jenkins

    docker compose up -d
  5. Access Jenkins

    http://<JENKINS_DOMAIN>:<JENKINS_HTTP_PORT>

Monitor Jenkins

docker compose logs -f

Destory Jenkins

docker compose down

kubernetes-plugin

Refer to kubernetes-plugin

Ensure the token and cert of servive account jenkins are set correctly.

How to get token and cert

How to get token and cert

Token

kubectl get secret $(kubectl get sa jenkins -o yaml | yq e '.secrets[0].name' -) -o yaml | yq e '.data.token' - | base64 -d

Cert

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.

  1. Web UI.

    1. Manage Jenkins -> Manage credentials -> jenkins-token-kubernetes -> Update -> Secret(Change password).
    2. Manage Jenkins -> Manage Nodes and Clouds -> Configure Clouds -> Kubernetes Cloud details -> Kubernetes server certificate key
  2. casc. Update the casc.yaml(Recomended)

    1. credentials -> system -> domainCredentials -> credentials -> string -> secret
    2. jenkins -> clouds -> kubernetes -> serverCertificate
    3. Reload configuration

Reference

Getting started with Jenkins Config as Code

Creating a Job DSL seed job with JCasC

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published