This project demonstrates a minimal CI/CD setup using Jenkins and Docker that triggers a pipeline whenever a GitHub pull request is merged into the main branch. The setup is designed to be easy to run, clean, and educational.
- Jenkins runs in Docker with pre-installed plugins for Git and GitHub integration.
- Automatically creates a pipeline job on startup.
- Runs a sample Python script as a build step.
- Skips the Jenkins setup wizard and creates a default admin user.
- Persistent Jenkins home volume for data storage.
- Docker
- Docker Compose
- GitHub repository (for webhook integration)
-
Clone this repository:
git clone https://github.com/hitibash/jenkins-python-webhook.git cd jenkins-python-webhook -
Build and start Jenkins using Docker Compose:
docker-compose up --build
-
Access Jenkins:
- Open http://localhost:8080 in your browser.
- Login with username:
admin, password:admin
-
Expose Jenkins to GitHub (for webhook delivery):
If running Jenkins locally, you need to expose your local server to the internet so GitHub can reach it. You can use either ngrok or smee.io:
-
Using ngrok:
- Download ngrok and install it.
- Run the following command to forward port 8080:
ngrok http 8080
- Copy the generated
https://xxxx.ngrok.ioURL.
-
Using smee.io:
- Go to https://smee.io and click "Start a new channel".
- Copy the generated smee URL (e.g.,
https://smee.io/your-channel-id). - Install smee-client:
npm install --global smee-client
- Forward events to your local Jenkins:
smee -u https://smee.io/your-channel-id --target http://localhost:8080/github-webhook/
-
-
Configure GitHub Webhook:
- Go to your GitHub repository settings.
- Add a webhook pointing to your public URL (from ngrok or smee.io), e.g.,
https://xxxx.ngrok.io/github-webhook/or your smee channel. - Set content type to
application/json. - Choose "Let me select individual events" and select "Pull request".
-
Test the Pipeline:
- Merge a pull request into the
mainbranch of your repository. - The Jenkins pipeline should trigger and run the sample Python script.
- Merge a pull request into the
dockerfile- Jenkins Docker image with Python and plugins.docker-compose.yml- Docker Compose configuration.plugins.txt- Jenkins plugins to install.scripts/disable_wizard.groovy- Disables Jenkins setup wizard and creates admin user.scripts/pipeline.groovy- Automatically creates the pipeline job.Jenkinsfile- Pipeline definition.main.py- Sample Python script.
- Edit
main.pyto change the script executed by the pipeline. - Modify
Jenkinsfileto add more build/test/deploy stages. - Update
scripts/pipeline.groovyto change job configuration.
To view Jenkins container logs, run:
docker compose logs jenkinsOpen the job's "Console Output" in Jenkins to see the Python script executed by the pipeline:
- Ensure Docker and Docker Compose are installed and running.
- If Jenkins plugins fail to install, try rebuilding the image.
- For webhook issues, verify your Jenkins server is accessible from GitHub.
- Make sure your ngrok tunnel or smee.io forwarding service is running and actively forwarding requests to your local Jenkins instance.


