-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
pipeline { | ||
agent any | ||
tools { | ||
jdk 'jdk17' | ||
maven 'maven3' | ||
} | ||
environment { | ||
SCANNER_HOME = tool 'sonar-scanner' | ||
} | ||
stages { | ||
stage('Git Checkout') { | ||
steps { | ||
git 'https://github.com/ChadenBA/Recipeapp.git' | ||
} | ||
} | ||
stage('Compile') { | ||
steps { | ||
sh "mvn compile" | ||
} | ||
} | ||
stage('Test') { | ||
steps { | ||
sh "mvn test" | ||
} | ||
} | ||
stage('File System Scan') { | ||
steps { | ||
sh "trivy fs --format table -o trivy-fs-report.html ." | ||
} | ||
} | ||
// Uncomment the following stages when needed | ||
/*stage('SonarQube Analsyis') { | ||
steps { | ||
withSonarQubeEnv('sonar') { | ||
sh ''' | ||
$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=recipeApp \ | ||
-Dsonar.projectKey=recipeApp \ | ||
-Dsonar.java.binaries=. | ||
''' | ||
} | ||
} | ||
} | ||
|
||
stage('Quality Gate') { | ||
steps { | ||
script { | ||
waitForQualityGate abortPipeline: false, credentialsId: 'sonar-token' | ||
} | ||
} | ||
}*/ | ||
|
||
stage('Build') { | ||
steps { | ||
sh "mvn package" | ||
} | ||
} | ||
|
||
stage('Publish To Nexus') { | ||
steps { | ||
withMaven(globalMavenSettingsConfig: 'global-settings', jdk: 'jdk17', maven: 'maven3', mavenSettingsConfig: '', traceability: true) { | ||
sh "mvn deploy" | ||
} | ||
} | ||
} | ||
|
||
stage('Build & Tag Docker Image') { | ||
steps { | ||
script { | ||
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') { | ||
sh "docker build -t chaden13/recipeapp:latest ." | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Docker Image Scan') { | ||
steps { | ||
sh "trivy image --format table -o trivy-image-report.html chaden13/recipeapp:latest " | ||
} | ||
} | ||
|
||
stage('Push Docker Image') { | ||
steps { | ||
script { | ||
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') { | ||
sh "docker push chaden13/recipeapp:latest " | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Deploy To Kubernetes') { | ||
steps { | ||
withKubeConfig(caCertificate: '', clusterName: 'kubernetes', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://192.168.1.56:6443') { | ||
sh "kubectl apply -f deployment-service.yml" | ||
} | ||
} | ||
} | ||
|
||
stage('Verify the Deployment') { | ||
steps { | ||
withKubeConfig(caCertificate: '', clusterName: 'kubernetes', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://192.168.1.56:6443') { | ||
sh "kubectl get pods -n webapps" | ||
sh "kubectl get svc -n webapps" | ||
} | ||
} | ||
} | ||
} | ||
} |