This project provides a customized Jenkins distribution for CI in a Box 2.0, offering a pre-configured Jenkins environment with essential plugins and configurations.
The distribution is designed to streamline the setup process for continuous integration and delivery pipelines, particularly for AWS-based infrastructures. It includes a comprehensive set of plugins for source control management, build automation, cloud integration, and security features.
Key features of this Jenkins distribution include:
- Pre-installed plugins for AWS, Docker, and various SCM systems
- Configuration as Code (JCasC) for easy setup and maintenance
- Integration with ciinabox-specific components
- Customizable job configurations and build strategies
- Support for cloud-based agent provisioning
Dockerfile
: Defines the custom Jenkins image builddocker-compose.yaml
: Configures the local development environmentjcasc.yaml
: Jenkins Configuration as Code fileplugins.yaml
: List of plugins to be installedinit.groovy.d/
: Contains initialization scriptsjcasc/
: Directory for JCasC related filesdefaults.yaml
: Default Jenkins configurationjcasc-apply.py
: Script to apply JCasC configurationsplugin-merger.py
: Script to merge plugin configurations
README.md
: This file, containing project documentation
Prerequisites:
- Docker and Docker Compose installed (version 19.03.0+)
- Git
Steps:
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Build and start the Jenkins container:
docker-compose up --build
-
Access Jenkins at
http://localhost:8080
The Jenkins instance is pre-configured using Jenkins Configuration as Code (JCasC). The main configuration file is jcasc/defaults.yaml
. To customize the configuration:
- Modify the
jcasc/defaults.yaml
file - Apply changes using the
jcasc-apply.py
script:python3 jcasc/jcasc-apply.py --jcasc-yaml jcasc/defaults.yaml
To add or update plugins:
- Edit the
plugins.yaml
file - Rebuild the Docker image:
docker-compose build
- Restart the Jenkins container:
docker-compose up -d
Job configurations can be customized using the Job DSL plugin. Add or modify job definitions in the jcasc/ciinabox-jobs
directory.
-
Jenkins fails to start:
- Check Docker logs:
docker-compose logs jenkins
- Verify JCasC configuration in
jcasc/defaults.yaml
- Ensure all required environment variables are set in
docker-compose.yaml
- Check Docker logs:
-
Plugin compatibility issues:
- Review
plugins.yaml
for version conflicts - Check Jenkins system logs for plugin-related errors
- Try updating problematic plugins to their latest versions
- Review
-
Configuration changes not applying:
- Ensure you've run the
jcasc-apply.py
script after making changes - Verify the JCASC_RELOAD_TOKEN is correctly set in the environment
- Check Jenkins logs for JCasC-related messages
- Ensure you've run the
-
AWS integration issues:
- Verify AWS credentials are correctly configured in Jenkins
- Check EC2 plugin configuration in
jcasc/defaults.yaml
- Ensure proper IAM permissions for the Jenkins instance
For more detailed debugging:
- Enable Jenkins debug logging by adding
-Djava.util.logging.config.file=/var/jenkins_home/log.properties
to JAVA_OPTS indocker-compose.yaml
- Inspect logs at
/var/jenkins_home/jenkins.log
inside the container
The Jenkins distribution follows this general data flow for job execution:
- User triggers a job or SCM webhook initiates a build
- Jenkins master receives the build request
- If using cloud agents, Jenkins provisions an EC2 instance via the EC2 plugin
- Job configuration is loaded from JCasC or Job DSL definitions
- Build steps are executed on the agent (or master for lightweight jobs)
- Build artifacts are stored (locally or in S3, depending on configuration)
- Build results are reported back to the Jenkins master
- Notifications are sent based on build status (email, Slack, etc.)
[User/SCM] -> [Jenkins Master] -> [EC2 Plugin] -> [EC2 Agent]
| |
v v
[Job Configuration] -----------------> [Build Execution]
| |
v v
[Artifact Storage] <----------------- [Build Results]
|
v
[Notifications/Reporting]
The infrastructure for this Jenkins distribution is primarily defined in the Dockerfile
and docker-compose.yaml
files. Key components include:
-
Docker:
Dockerfile
: Defines the custom Jenkins image based onjenkins/jenkins:2.479.2-jdk17
docker-compose.yaml
: Configures the Jenkins service for local development
-
Jenkins:
- Exposed ports: 8080 (web interface), 50000 (agent communication)
- Volume mounts:
/var/run/docker.sock
: Allows Jenkins to interact with the Docker daemon./jcasc.yaml
: Mounts the JCasC configuration file
-
Environment variables:
CASC_JENKINS_CONFIG
: Specifies the location of the JCasC configurationTRY_UPGRADE_IF_NO_MARKER
: Enables automatic plugin upgradesPLUGINS_FORCE_UPGRADE
: Forces plugin upgradesJCASC_RELOAD_TOKEN
: Token for reloading JCasC configurationJAVA_OPTS
: Various Java options for Jenkins, including security settings
-
AWS (configured in
jcasc/defaults.yaml
):- EC2 plugin configuration for provisioning cloud agents
- IAM instance profile (not specified in provided files)
- Security groups and subnets for EC2 instances
Note: Specific AWS resource identifiers (e.g., AMI IDs, security group IDs) are placeholders in the provided configuration and should be replaced with actual values for production use.