diff --git a/Jenkinsfile b/Jenkinsfile
index b77cce31..5fd0f03d 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -7,6 +7,7 @@ pipeline{
agent any
environment{
Docker_tag = getDockerTag()
+ docker_pws = credentials('docker-password')
}
stages{
stage("Sonar scan"){
@@ -50,19 +51,69 @@ pipeline{
steps{
script{
sh """
- printenv
- cp -r ../sample-web-app-pull-request@2/target .
+ cp -r ../$JOB_BASE_NAME@2/target .
docker build . -t 34.125.26.221:8083/sample-app:$Docker_tag
"""
}
}
}
+
+ stage('docker login & push'){
+ steps{
+ script{
+ sh """
+ docker login -u admin -p $docker_pws 34.125.26.221:8083
+ docker push 34.125.26.221:8083/sample-app:$Docker_tag
+ """
+ addBadge(icon: 'save.gif', text: 'docker repo', link: 'http://34.125.26.221:8081/#browse/browse:docker-hosted:v2%2Fsample-app')
+ currentBuild.description = "sample-app:$Docker_tag"
+ }
+ }
+ }
+
+ stage('authenticate and prepare k8s manifest files'){
+ steps{
+ script{
+ configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
+ sh '''
+ kubectl get po
+ final_tag=$(echo $Docker_tag | tr -d ' ')
+ sed -i "s|TAG|$final_tag|" deployment.yaml
+ cat deployment.yaml
+ '''
+ }
+ }
+ }
+ }
+
+ 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('deploy to k8s cluster'){
+ steps{
+ script{
+ configFileProvider([configFile(fileId: 'kube-dev-config', variable: 'KUBECONFIG')]) {
+ sh '''
+ kubectl apply -f deployment.yaml
+ '''
+ }
+ }
+ }
+ }
}
- // post {
- // always{
- // cleanWs()
- // }
- // }
+ post {
+ always{
+ cleanWs()
+ }
+ }
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 78662a2a..9284772e 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,11 @@
```
mvn clean package
-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..bb466fc2 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-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