Ensure you have the following installed on your macOS:
- Homebrew (
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
) - OpenJDK (
brew install openjdk
) - Docker & Docker Compose (
brew install --cask docker
and then open Docker app) - ngrok or Cloudflared for exposing local Jenkins to the internet
brew install jenkins-lts
brew services start jenkins-lts
Open your browser and go to:
http://localhost:8080
Retrieve the initial admin password:
cat /Users/$(whoami)/.jenkins/secrets/initialAdminPassword
Set up your admin credentials and install recommended plugins.
Since Jenkins runs as a service (not a user) on macOS, update its environment variables:
- Go to Jenkins Dashboard → Manage Jenkins → Manage Nodes and Clouds
- Click Built-In Node → Configure
- Enable "Environment Variables" under Node Properties
- Add the following:
- Name:
PATH
- Value:
/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin
- Name:
- Save and restart Jenkins:
brew services restart jenkins-lts
- Expose Jenkins to the Internet
- Using ngrok:
ngrok http 8080
- Using Cloudflared:
cloudflared tunnel --url http://localhost:8080
- Using ngrok:
- Copy the public URL and add it to GitHub webhook settings:
- Go to your GitHub repository → Settings → Webhooks
- Add webhook URL:
<your-ngrok-url>/github-webhook/
- Choose "Send everything" and save.
pipeline {
agent any
stages {
stage("Clone Code") {
steps {
echo "Started Cloning Code from GitHub"
git url: "https://github.com/raza1315/jenkins.git" , branch: "main"
}
}
stage("Deploy") {
steps {
echo "Running Docker Compose to Start Container"
sh "docker compose down"
sh "docker-compose up -d --build"
}
}
}
post {
success {
echo 'Server deployed successfully!'
}
failure {
echo 'Deployment failed!'
}
}
}
- Go to Jenkins Dashboard → New Item
- Select Pipeline and enter a job name
- Under Pipeline Definition, select "Pipeline script from SCM"
- Enter your GitHub repo URL and branch name
- Enable "GitHub hook trigger for GITScm polling"
- Save and Build Now
Check running containers:
docker ps
View logs if needed:
docker-compose logs -f
Your app should now be running and automatically redeployed on github pushes!