This is a simple DevOps CI/CD pipeline project using Jenkins, Docker, and GitHub. The pipeline builds a Docker image and pushes it to Docker Hub using Jenkins stages.
Builds the Docker image from the Dockerfile.
Pushes the Docker image to your Docker Hub account.
``` . ├── Jenkinsfile ├── Dockerfile ├── app/ (your application code) └── README.md ```
```bash git init ```
```bash git add . ```
```bash git commit -m "Initial commit: add Dockerfile and Jenkinsfile" ```
```bash git remote add origin https://github.com/YOUR_USERNAME/ai-devops-pipeline1.git ```
```bash git branch -M main git push -u origin main ```
```bash docker build -t your-dockerhub-username/your-image-name . ```
```bash docker login ```
```bash docker push your-dockerhub-username/your-image-name ```
- Create a Pipeline in Jenkins named `ai-devops-pipeline1`.
- Use `Pipeline script from SCM`.
- Connect your GitHub repo.
- Jenkinsfile content:
```groovy pipeline { agent any
stages {
stage('Build Docker Image') {
steps {
sh 'docker build -t your-dockerhub-username/your-image-name .'
}
}
stage('Push Docker Image') {
steps {
withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh 'echo \$DOCKER_PASS | docker login -u \$DOCKER_USER --password-stdin'
sh 'docker push your-dockerhub-username/your-image-name'
}
}
}
}
} ```
- Replace `your-dockerhub-username/your-image-name` with your actual Docker Hub repo.
- Replace `docker-hub-credentials` with the correct Jenkins credential ID.
Once pushed, Jenkins will automatically:
- Clone the repo.
- Build the Docker image.
- Push it to Docker Hub.