Skip to content

Commit

Permalink
Create jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadenBA authored Apr 27, 2024
1 parent 5f337e3 commit 00b3e41
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions jenkins
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"
}
}
}
}
}

0 comments on commit 00b3e41

Please sign in to comment.