From 270afd3ae93389eeb2bfda516f297fdcf8f68802 Mon Sep 17 00:00:00 2001 From: Jyoti-Hariwal <81757935+Jyoti-Hariwal@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:18:27 +0530 Subject: [PATCH 1/5] Create jenkins --- jenkins | 1 + 1 file changed, 1 insertion(+) create mode 100644 jenkins diff --git a/jenkins b/jenkins new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/jenkins @@ -0,0 +1 @@ + From 19116f9d3bb0db8ed99222699860d335ee657de7 Mon Sep 17 00:00:00 2001 From: Jyoti-Hariwal <81757935+Jyoti-Hariwal@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:21:59 +0530 Subject: [PATCH 2/5] Update jenkins --- jenkins | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/jenkins b/jenkins index 8b137891..db5e9bef 100644 --- a/jenkins +++ b/jenkins @@ -1 +1,43 @@ +pipeline { + environment { + registry = "Jyoti-Hariwal/counter-app" + registryCredential = 'dockerhub' + KUBECONFIG="$JENKINS_HOME/.kube/config1" + } + agent any + stages { + stage('Building image') { + steps{ + sh "printenv" + + sh "docker build -t jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME ." + //sh "docker run -dp 80:80 jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME" + sh "docker push jyoti26/calculator:$BUILD_ID-$BRANCH_NAME" + } + } + stage('Creating Deployment') { + steps { + + sh '''#!/bin/bash + + if [[ $GIT_BRANCH == "namespace2" ]] + then + kubectl set image deployment/jyoti nginx=jyoti26/calculator:$BUILD_ID-$BRANCH_NAME -n $BRANCH_NAME + elif [[ $GIT_BRANCH == "master" ]] + then + kubectl set image deployment/jyoti nginx=jyoti26/calculator:$BUILD_ID-$BRANCH_NAME -n namespace2 + fi + ''' + } + } + stage('') { + steps{ + sh ''' + + kubectl get svc -n $BRANCH_NAME + ''' + } + } + } +} From 2986df4672b55a57ef9fc48b9e2b763d23ea2a6e Mon Sep 17 00:00:00 2001 From: Jyoti-Hariwal <81757935+Jyoti-Hariwal@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:29:41 +0530 Subject: [PATCH 3/5] Rename jenkins to Jenkinsfile --- jenkins => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jenkins => Jenkinsfile (100%) diff --git a/jenkins b/Jenkinsfile similarity index 100% rename from jenkins rename to Jenkinsfile From 39647a94863e02fd4106b6fdc82c77913ce557ea Mon Sep 17 00:00:00 2001 From: Jyoti-Hariwal <81757935+Jyoti-Hariwal@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:37:28 +0530 Subject: [PATCH 4/5] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index db5e9bef..b44d52fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { sh "docker build -t jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME ." //sh "docker run -dp 80:80 jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME" - sh "docker push jyoti26/calculator:$BUILD_ID-$BRANCH_NAME" + sh "docker push jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME" } } stage('Creating Deployment') { @@ -22,10 +22,10 @@ pipeline { if [[ $GIT_BRANCH == "namespace2" ]] then - kubectl set image deployment/jyoti nginx=jyoti26/calculator:$BUILD_ID-$BRANCH_NAME -n $BRANCH_NAME + kubectl set image deployment/jyoti nginx=jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME -n $BRANCH_NAME elif [[ $GIT_BRANCH == "master" ]] then - kubectl set image deployment/jyoti nginx=jyoti26/calculator:$BUILD_ID-$BRANCH_NAME -n namespace2 + kubectl set image deployment/jyoti nginx=jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME -n namespace2 fi ''' } From dd489aa88be47a1200da6c9154cf9140ff5267e5 Mon Sep 17 00:00:00 2001 From: Jyoti-Hariwal <81757935+Jyoti-Hariwal@users.noreply.github.com> Date: Fri, 2 Jul 2021 17:03:20 +0530 Subject: [PATCH 5/5] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b44d52fe..a760d9f0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,7 +25,7 @@ pipeline { kubectl set image deployment/jyoti nginx=jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME -n $BRANCH_NAME elif [[ $GIT_BRANCH == "master" ]] then - kubectl set image deployment/jyoti nginx=jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME -n namespace2 + kubectl set image deployment/jyoti nginx=jyoti26/counter-app:$BUILD_ID-$BRANCH_NAME -n namespace1 fi ''' }