diff --git a/Jenkinsfile b/Jenkinsfile index 4265b450..0cc85334 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,13 @@ +def getDockerTag(){ + def tag = sh script: 'git rev-parse --short HEAD', returnStdout: true + return tag + } + pipeline{ agent any + environment{ + Docker_tag = getDockerTag() + } stages{ stage("Sonar scan"){ agent { @@ -38,11 +46,52 @@ pipeline{ } } + stage('docker login and build'){ + steps{ + script{ + sh """ + docker login -u admin -p admin 34.125.26.221:8083 + cp -r ../ci-pull-request@2/target . + docker build . -t 34.125.26.221:8083/sample-web-app:$Docker_tag + docker push 34.125.26.221:8083/sample-web-app:$Docker_tag + """ + + } + } + } + + stage('prepare deplyment file'){ + steps{ + script{ + sh ''' + final_tag=$(echo $Docker_tag | tr -d ' ') + sed -i "s|TAG|$final_tag|" deployment.yaml + cat deployment.yaml + ''' + } + } + } + stage('connect k8s cluster'){ + steps{ + script{ + configFileProvider( + [configFile(fileId: 'kube-config-file', variable: 'KUBECONFIG')]) { + sh """ + kubectl get po + kubectl apply -f deployment.yaml + """ + } + } + } + } + + } post { always{ cleanWs() + sh 'kubectl delete -f deployment.yaml' } } } \ No newline at end of file diff --git a/README.md b/README.md index 78662a2a..94ba7cd3 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,3 @@ and build the instruction . # Deploy instruction Deploy ```target/WebApp.war``` on Tomcat properly for better experience. - diff --git a/deployment.yaml b/deployment.yaml index 08bfdcc7..ac7d9566 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -13,7 +13,7 @@ spec: spec: containers: - name: devops-training - image: deekshithsn/webapp:TAG + image: 34.125.26.221/sample-web-app:TAG command: ["/bin/sh"] args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"] ports: diff --git a/pom.xml b/pom.xml index 9b43cb6e..8491d28a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ lu.amazon.aws.demo WebApp war - 2.0 + 2.0-SNAPSHOT WebApp Maven Webapp http://maven.apache.org diff --git a/test b/test deleted file mode 100644 index 03e0cd9a..00000000 --- a/test +++ /dev/null @@ -1,3 +0,0 @@ -My changes -A B -githubtrigger