-
Notifications
You must be signed in to change notification settings - Fork 367
Added Jenkinsfile & also jenkins output images stepwise #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: DevOps
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pipeline { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| agent { label 'spring-server' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| stages { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| stage("Code Clone") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Code Clone Stage" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| git url: "https://github.com/shailesh271997/Springboot-BankApp.git", branch: "nginx-setup" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve Git checkout configuration. Several improvements are recommended for the Code Clone stage:
- stage("Code Clone") {
+ stage("Checkout") {
steps {
- echo "Code Clone Stage"
- git url: "https://github.com/shailesh271997/Springboot-BankApp.git", branch: "nginx-setup"
+ cleanWs()
+ checkout scm
}
}If you need to keep the explicit git step, consider using parameters: parameters {
string(name: 'BRANCH_NAME', defaultValue: 'nginx-setup', description: 'Git branch to build')
} |
||||||||||||||||||||||||||||||||||||||||||||||||||
| stage("Code Build & Test") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Code Build Stage" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sh "docker build -t springboot-bankapp ." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhance build stage with tests and proper versioning. The current build stage has several missing components:
stage("Code Build & Test") {
steps {
- echo "Code Build Stage"
- sh "docker build -t springboot-bankapp ."
+ script {
+ def version = env.BUILD_NUMBER
+ // Run tests
+ sh "./mvnw clean test"
+ // Build with proper tags and cache
+ sh """
+ docker build \
+ --cache-from springboot-bankapp:latest \
+ -t springboot-bankapp:${version} \
+ -t springboot-bankapp:latest \
+ --build-arg VERSION=${version} \
+ .
+ """
+ }
}
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| stage("Push To DockerHub") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| withCredentials([usernamePassword( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| credentialsId: "dockerHubCreds", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usernameVariable: "dockerHubUser", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| passwordVariable: "dockerHubPass")]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sh 'echo $dockerHubPass | docker login -u $dockerHubUser --password-stdin' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sh "docker image tag springboot-bankapp ${env.dockerHubUser}/springboot-bankapp:latest" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sh "docker push ${env.dockerHubUser}/springboot-bankapp:latest" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add security scanning and error handling to Docker push stage. The current stage needs security and reliability improvements:
stage("Push To DockerHub") {
steps {
- withCredentials([usernamePassword(
- credentialsId: "dockerHubCreds",
- usernameVariable: "dockerHubUser",
- passwordVariable: "dockerHubPass")]) {
- sh 'echo $dockerHubPass | docker login -u $dockerHubUser --password-stdin'
- sh "docker image tag springboot-bankapp ${env.dockerHubUser}/springboot-bankapp:latest"
- sh "docker push ${env.dockerHubUser}/springboot-bankapp:latest"
+ script {
+ def version = env.BUILD_NUMBER
+ try {
+ // Scan for vulnerabilities
+ sh "trivy image springboot-bankapp:${version}"
+
+ withCredentials([usernamePassword(
+ credentialsId: "dockerHubCreds",
+ usernameVariable: "dockerHubUser",
+ passwordVariable: "dockerHubPass")]) {
+ sh '''
+ echo $dockerHubPass | docker login -u $dockerHubUser --password-stdin docker.io
+ docker image tag springboot-bankapp:${version} docker.io/${dockerHubUser}/springboot-bankapp:${version}
+ docker image tag springboot-bankapp:${version} docker.io/${dockerHubUser}/springboot-bankapp:latest
+ docker push docker.io/${dockerHubUser}/springboot-bankapp:${version}
+ docker push docker.io/${dockerHubUser}/springboot-bankapp:latest
+ '''
+ }
+ } catch (Exception e) {
+ error "Failed to push image: ${e.message}"
+ } finally {
+ sh 'docker logout'
+ // Clean up local images
+ sh "docker rmi springboot-bankapp:${version} || true"
+ }
}
}
}
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| stage("Deploy") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| steps { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sh "docker compose down && docker compose up -d --build" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve deployment reliability and add health checks. The current deployment strategy has several concerns:
stage("Deploy") {
steps {
- sh "docker compose down && docker compose up -d --build"
+ script {
+ try {
+ // Verify docker-compose.yml exists
+ sh '[ -f docker-compose.yml ] || (echo "docker-compose.yml not found" && exit 1)'
+
+ // Rolling update to avoid downtime
+ sh '''
+ docker compose pull
+ docker compose up -d --no-deps --build app
+
+ # Wait for health check
+ timeout 60s bash -c 'until curl -s http://localhost:8080/actuator/health | grep -q "UP"; do sleep 5; done'
+ '''
+ } catch (Exception e) {
+ echo "Deployment failed, rolling back..."
+ sh 'docker compose rollback app'
+ error "Failed to deploy: ${e.message}"
+ }
+ }
}
}
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add timeout and resource constraints to the pipeline.
Consider adding pipeline-level timeout and resource constraints to prevent hung builds and resource exhaustion:
pipeline { agent { label 'spring-server' } + options { + timeout(time: 1, unit: 'HOURS') + } + resources { + memory '2048Mi' + cpu '500m' + }