diff --git a/jenkins b/jenkins new file mode 100644 index 00000000..bb1c3e63 --- /dev/null +++ b/jenkins @@ -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" + } + } + } + } +}