Skip to content

Commit

Permalink
Update Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
LondheShubham153 authored Mar 3, 2024
1 parent 12fa27f commit f4929a0
Showing 1 changed file with 34 additions and 45 deletions.
79 changes: 34 additions & 45 deletions DevSecOps/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
pipeline{
pipeline {

agent any
environment{
SONAR_HOME= tool "Sonar"
SONAR_HOME = tool "Sonar"
}
stages{
stage("Code Checkout"){
steps{
git url:"https://github.com/DevMadhup/node-todo-cicd.git", branch:"master"
}
}
stages {

stage("SonarQube Analysis"){
stage("Code"){
steps{
withSonarQubeEnv("Sonar"){
sh "$SONAR_HOME/bin/sonar-scanner -Dsonar.projectName=nodetodo -Dsonar.projectKey=nodetodo -X"
}
git url: "https://github.com/LondheShubham153/node-todo-cicd.git" , branch: "master"
echo "Code Cloned Successfully"
}
}

stage("SonarQube Quality Gates"){
steps{
timeout(time: 1, unit: "MINUTES"){
waitForQualityGate abortPipeline: false
}
}
}

stage("OWASP Dependency Check"){
stage("Build & Test"){
steps{
dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'dc'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
sh 'docker build -t node-app-batch-6:latest .'
echo "Code Built Successfully"
}
}

stage("Docker Code Build"){
stage("SonarQube Analysis"){
steps{
sh "docker build -t nodeapp ."
withSonarQubeEnv("Sonar"){
sh "$SONAR_HOME/bin/sonar-scanner -Dsonar.projectName=nodetodo -Dsonar.projectKey=nodetodo -X"
}
}
}

stage("Docker Code Scan: Trivy"){
stage("SonarQube Quality Gates"){
steps{
sh "trivy image nodeapp"
timeout(time: 1, unit: "MINUTES"){
waitForQualityGate abortPipeline: false
}
}
}

stage("Docker Build Push: DockerHub"){
stage("OWASP"){
steps{
withCredentials([usernamePassword(credentialsId:"DockerCred",passwordVariable:"dockerhubpass",usernameVariable:"dockerhubname")]){
sh "docker logout"
sh "docker login -u ${env.dockerhubname} -p ${env.dockerhubpass}"
}
dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'OWASP'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}

stage("Docker Tag"){
stage("Trivy"){
steps{
sh "docker tag nodeapp:latest trainwithshubham/nodeapp:latest"
sh "trivy image node-app-batch-6"
}
}

stage("Code Push to DockerHub"){
stage("Push to Private Docker Hub Repo"){
steps{
sh "docker push trainwithshubham/nodeapp:latest"
withCredentials([usernamePassword(credentialsId:"DockerHubCreds",passwordVariable:"dockerPass",usernameVariable:"dockerUser")]){
sh "docker login -u ${env.dockerUser} -p ${env.dockerPass}"
sh "docker tag node-app-batch-6:latest ${env.dockerUser}/node-app-batch-6:latest"
sh "docker push ${env.dockerUser}/node-app-batch-6:latest"
}

}
}

stage("Code Deploy"){
steps{
sh "docker-compose down && docker-compose up -d"
stage("Deploy"){
steps{
sh "docker-compose up -d"
echo "App Deployed Successfully"
}
}
}
Expand Down

0 comments on commit f4929a0

Please sign in to comment.