diff --git a/Jenkinsfile b/Jenkinsfile
index b6c34792..a7268075 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,79 +1,109 @@
-currentBuild.displayName = "Final_Demo # "+currentBuild.number
-
- def getDockerTag(){
+def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
- }
-
+ }
-pipeline{
- agent any
- environment{
- Docker_tag = getDockerTag()
- }
-
- stages{
+pipeline {
+ agent any
+ environment{
+ Docker_tag = getDockerTag()
+ Docker_Creds = credentials('dockerhub-creds')
+ }
- stage('Quality Gate Statuc Check'){
+ stages {
+ stage('static code anaylysis'){
+
+ agent{
+ docker{
+ image 'maven:3.6.0'
+ }
+ }
- agent {
- docker {
- image 'maven'
- args '-v $HOME/.m2:/root/.m2'
+ steps {
+ script{
+ withSonarQubeEnv(credentialsId: 'sonartoken') {
+ sh 'printenv'
+ sh "mvn sonar:sonar"
}
+
+ // timeout(5){
+ // def qg = waitForQualityGate()
+ // if (qg.status != 'OK'){
+ // error "code didnt met qulaity gate"
+ // }
+ // }
+
+ }
}
- steps{
- script{
- withSonarQubeEnv('sonarserver') {
- sh "mvn sonar:sonar"
- }
- timeout(time: 1, unit: 'HOURS') {
- def qg = waitForQualityGate()
- if (qg.status != 'OK') {
- error "Pipeline aborted due to quality gate failure: ${qg.status}"
- }
- }
- sh "mvn clean install"
- }
- }
+ }
+
+ stage('build') {
+
+ agent{
+ docker{
+ image 'maven:3.6.0'
+ args '-v /root/.m2:/root/.m2'
}
+ }
+ steps{
+ script{
+ sh "mvn clean install"
+ }
+ }
+ }
+ stage('docker build & docker push') {
+ steps{
+ script{
+ sh """
+ cp -r ../complete-pipeline@2/target .
+ docker build . -t deekshithsn/webapp-demo:$Docker_tag
+ docker login -u $Docker_Creds_USR -p $Docker_Creds_PSW
+ docker push deekshithsn/webapp-demo:$Docker_tag
+ """
+ currentBuild.description = "$Docker_tag"
+ addBadge(icon: 'save.gif' , link: 'https://hub.docker.com/repository/docker/deekshithsn/webapp-demo/tags')
+ }
+ }
+ }
- stage('build')
- {
- steps{
- script{
- sh 'cp -r ../devops-training@2/target .'
- sh 'docker build . -t deekshithsn/devops-training:$Docker_tag'
- withCredentials([string(credentialsId: 'docker_password', variable: 'docker_password')]) {
-
- sh 'docker login -u deekshithsn -p $docker_password'
- sh 'docker push deekshithsn/devops-training:$Docker_tag'
- }
- }
+ stage('approval stage') {
+ steps{
+ script{
+ timeout(5){
+ // mail bcc: '', body: "
Project: ${env.JOB_NAME}
Build Number: ${env.BUILD_NUMBER}
URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "${currentBuild.result} CI: Project name -> ${env.JOB_NAME}", to: "deekshithsn@gmail.com";
+ input( message: "Deploy ${params.project_name}?", ok: 'Deploy')
}
- }
-
- stage('ansible playbook'){
- steps{
- script{
- sh '''final_tag=$(echo $Docker_tag | tr -d ' ')
- echo ${final_tag}test
- sed -i "s/docker_tag/$final_tag/g" deployment.yaml
- '''
- ansiblePlaybook become: true, installation: 'ansible', inventory: 'hosts', playbook: 'ansible.yaml'
- }
- }
- }
-
-
-
- }
-
-
-
-
-
-}
+ }
+ }
+ }
+
+ stage('deploy stage'){
+ steps{
+ script{
+ sh '''
+ final_tag=$(echo $Docker_tag | tr -d ' ')
+ sed -i "s;IMAGE_NAME;deekshithsn/webapp-demo:$final_tag;" deployment.yaml
+ cat deployment.yaml
+ '''
+ }
+ }
+ }
+
+
+ stage('deploy to k8s cluster'){
+ steps{
+ script{
+ configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
+ sh '''
+ kubectl apply -f deployment.yaml
+ '''
+ }
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/deployment.yaml b/deployment.yaml
index 55d9da8b..b444e1db 100644
--- a/deployment.yaml
+++ b/deployment.yaml
@@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: devops-training
- image: deekshithsn/devops-training:docker_tag
+ image: IMAGE_NAME
command: ["/bin/sh"]
args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"]
ports:
diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp
index 9fda98e7..7db67b71 100644
--- a/src/main/webapp/index.jsp
+++ b/src/main/webapp/index.jsp
@@ -71,6 +71,11 @@
Jenkins is a free and open source automation server. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery
+Kubernetes is a free and open source automation server. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery
+ +Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.