diff --git a/DevSecOps/Jenkinsfile b/DevSecOps/Jenkinsfile index ab2c74bd6..6fb1feb55 100644 --- a/DevSecOps/Jenkinsfile +++ b/DevSecOps/Jenkinsfile @@ -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" } } }