From 76f08969d1d46ca210146539d0a52d6562e86031 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 11:03:45 +0530 Subject: [PATCH 01/30] added docker file --- Dockerfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..9f57a2fb2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.22.5 as base + +WORKDIR /app + +COPY go.mod ./ + +RUN go mod download + +COPY . . + +RUN go build -o main . + + +FROM gcr.io/distroless/base + +COPY --from=base /app/main . + +COPY --from=base /app/static ./static + +EXPOSE 8080 + +CMD [ "./main" ] \ No newline at end of file From 804490f66a3bf7379678ca3e0077ed2b811035f4 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 14:07:42 +0530 Subject: [PATCH 02/30] added jenkins file --- Jenkinsfile | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..fdb752900 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,75 @@ +pipeline { + agent any + + tools { + go 'go-1.22.5' + } + + + environment { + + SCANNER_HOME = tool 'sonar-scanner' + SONAR_TOKEN = credentials('sonar-cred') + + } + + stages { + + stage('Build'){ + steps{ + sh "go build -o go-web-app" + } + } + + stage('Unit Test') { + steps { + sh "go test ./..." + } + } + + stage('Run SonarQube Analysis') { + steps { + script { + sh ''' + ${SCANNER_HOME}/bin/sonar-scanner \ + -Dsonar.projectKey=gowebapp \ + -Dsonar.sources=. \ + -Dsonar.host.url=http://localhost:9000 \ + -Dsonar.login=${SONAR_TOKEN} + ''' + } + } + } + + stage('Docker Build & Tag') { + steps { + + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') + { + sh 'docker build -t vinay7944/go-web-app:latest .' + } + } + } + } + + stage('Docker Push image'){ + steps{ + script{ + withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ + sh "docker push vinay7944/go-web-app:latest" + } + } + } + } + + + } + + + post{ + always{ + echo "complete" + } + } +} From cd2fd22717c92761a540baac74a50201fc3c8670 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 14:20:44 +0530 Subject: [PATCH 03/30] modified jenkins file --- Jenkinsfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fdb752900..6142451a8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,15 +29,10 @@ pipeline { stage('Run SonarQube Analysis') { steps { - script { - sh ''' - ${SCANNER_HOME}/bin/sonar-scanner \ - -Dsonar.projectKey=gowebapp \ - -Dsonar.sources=. \ - -Dsonar.host.url=http://localhost:9000 \ - -Dsonar.login=${SONAR_TOKEN} - ''' + withSonarQubeEnv('sonar'){ + sh "${SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectKey=gowebapp -Dsonar.projectName=gowebapp" } + } } From 33833db3e4e4c3cf5f7e13c46936b4a5f652fcee Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 14:36:34 +0530 Subject: [PATCH 04/30] added running conatiner step in jenklins file --- Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 6142451a8..33fb040e8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,6 +58,16 @@ pipeline { } } + stage('Docker deploy to local'){ + steps{ + script{ + withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ + sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" + } + } + } + } + } From e5268989d26f691ae4084980df3efdee3ec75d46 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 14:56:30 +0530 Subject: [PATCH 05/30] modified jenkins file --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 33fb040e8..49c2e542f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,7 +62,7 @@ pipeline { steps{ script{ withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" + sh "docker run -d -p 8080:8080 --name gowebapp vinay7944/go-web-app:latest" } } } From 3595212a9bb9996529e31c56cc818f31071ad3e7 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 15:14:24 +0530 Subject: [PATCH 06/30] added comment to check webhook --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index b04eee299..4d7c60351 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ func homePage(w http.ResponseWriter, r *http.Request) { } func coursePage(w http.ResponseWriter, r *http.Request) { - // Render the course html page + // Render the course html page of the chaneg by vinay http.ServeFile(w, r, "static/courses.html") } From 70d8bf95e05603e37212065f2259193501c4e702 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 15:18:21 +0530 Subject: [PATCH 07/30] changed port --- Dockerfile | 2 +- Jenkinsfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f57a2fb2..762fe068e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,6 @@ COPY --from=base /app/main . COPY --from=base /app/static ./static -EXPOSE 8080 +EXPOSE 3000 CMD [ "./main" ] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 49c2e542f..33fb040e8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,7 +62,7 @@ pipeline { steps{ script{ withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - sh "docker run -d -p 8080:8080 --name gowebapp vinay7944/go-web-app:latest" + sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" } } } From c87e9d5e1f7c0e14eefc82f215268f85d41dd168 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Wed, 14 Aug 2024 15:21:18 +0530 Subject: [PATCH 08/30] changed port --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 33fb040e8..9b4dd785c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,7 +71,6 @@ pipeline { } - post{ always{ echo "complete" From d3f77e0899f0d756cd18b0cd67225452fb3f3d74 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 12:24:34 +0530 Subject: [PATCH 09/30] edited jenkins file and added k8 and helm files --- Jenkinsfile | 22 ++++++++--------- helm/go-web-app-chart/.helmignore | 23 ++++++++++++++++++ helm/go-web-app-chart/Chart.yaml | 24 +++++++++++++++++++ .../templates/deployment.yaml | 21 ++++++++++++++++ helm/go-web-app-chart/templates/ingress.yaml | 20 ++++++++++++++++ helm/go-web-app-chart/templates/service.yaml | 15 ++++++++++++ helm/go-web-app-chart/values.yaml | 23 ++++++++++++++++++ k8/manifests/deployment.yaml | 21 ++++++++++++++++ k8/manifests/ingress.yaml | 20 ++++++++++++++++ k8/manifests/service.yaml | 15 ++++++++++++ 10 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 helm/go-web-app-chart/.helmignore create mode 100644 helm/go-web-app-chart/Chart.yaml create mode 100644 helm/go-web-app-chart/templates/deployment.yaml create mode 100644 helm/go-web-app-chart/templates/ingress.yaml create mode 100644 helm/go-web-app-chart/templates/service.yaml create mode 100644 helm/go-web-app-chart/values.yaml create mode 100644 k8/manifests/deployment.yaml create mode 100644 k8/manifests/ingress.yaml create mode 100644 k8/manifests/service.yaml diff --git a/Jenkinsfile b/Jenkinsfile index 9b4dd785c..a0eb4ce46 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { script { withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { - sh 'docker build -t vinay7944/go-web-app:latest .' + sh 'docker build -t vinay7944/go-web-app:v1 .' } } } @@ -52,21 +52,21 @@ pipeline { steps{ script{ withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - sh "docker push vinay7944/go-web-app:latest" + sh "docker push vinay7944/go-web-app:v1" } } } } - stage('Docker deploy to local'){ - steps{ - script{ - withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" - } - } - } - } + // stage('Docker deploy to local'){ + // steps{ + // script{ + // withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ + // sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" + // } + // } + // } + // } } diff --git a/helm/go-web-app-chart/.helmignore b/helm/go-web-app-chart/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/helm/go-web-app-chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/go-web-app-chart/Chart.yaml b/helm/go-web-app-chart/Chart.yaml new file mode 100644 index 000000000..5d5e4a81b --- /dev/null +++ b/helm/go-web-app-chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: go-web-app-chart +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/helm/go-web-app-chart/templates/deployment.yaml b/helm/go-web-app-chart/templates/deployment.yaml new file mode 100644 index 000000000..c1967ce73 --- /dev/null +++ b/helm/go-web-app-chart/templates/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + replicas: 1 + selector: + matchLabels: + app: go-web-app + template: + metadata: + labels: + app: go-web-app + spec: + containers: + - name: go-web-app + image: vinay7944/go-web-app:v1 + ports: + - containerPort: 8080 diff --git a/helm/go-web-app-chart/templates/ingress.yaml b/helm/go-web-app-chart/templates/ingress.yaml new file mode 100644 index 000000000..39122ef40 --- /dev/null +++ b/helm/go-web-app-chart/templates/ingress.yaml @@ -0,0 +1,20 @@ +# Ingress resource for the application +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: go-web-app + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - host: go-web-app.local + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: go-web-app + port: + number: 80 diff --git a/helm/go-web-app-chart/templates/service.yaml b/helm/go-web-app-chart/templates/service.yaml new file mode 100644 index 000000000..567a904a1 --- /dev/null +++ b/helm/go-web-app-chart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + selector: + app: go-web-app + type: ClusterIP + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + diff --git a/helm/go-web-app-chart/values.yaml b/helm/go-web-app-chart/values.yaml new file mode 100644 index 000000000..d54f5546b --- /dev/null +++ b/helm/go-web-app-chart/values.yaml @@ -0,0 +1,23 @@ +# Default values for go-web-app-chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: abhishekf5/go-web-app + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "v1" + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific \ No newline at end of file diff --git a/k8/manifests/deployment.yaml b/k8/manifests/deployment.yaml new file mode 100644 index 000000000..955174f4e --- /dev/null +++ b/k8/manifests/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + replicas: 1 + selector: + matchLabels: + app: go-web-app + template: + metadata: + labels: + app: go-web-app + spec: + containers: + - name: go-web-app + image: vinay7944/go-web-app:{{ .Values.image.tag }} + ports: + - containerPort: 8080 diff --git a/k8/manifests/ingress.yaml b/k8/manifests/ingress.yaml new file mode 100644 index 000000000..39122ef40 --- /dev/null +++ b/k8/manifests/ingress.yaml @@ -0,0 +1,20 @@ +# Ingress resource for the application +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: go-web-app + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - host: go-web-app.local + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: go-web-app + port: + number: 80 diff --git a/k8/manifests/service.yaml b/k8/manifests/service.yaml new file mode 100644 index 000000000..567a904a1 --- /dev/null +++ b/k8/manifests/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: go-web-app + labels: + app: go-web-app +spec: + selector: + app: go-web-app + type: ClusterIP + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + From 9a7495813bdd41301caa88c45dc99d8c3fa9d851 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 12:37:29 +0530 Subject: [PATCH 10/30] edited docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 762fe068e..9f57a2fb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,6 @@ COPY --from=base /app/main . COPY --from=base /app/static ./static -EXPOSE 3000 +EXPOSE 8080 CMD [ "./main" ] \ No newline at end of file From 15fa605d20e0ff957345023d856201efb4061f9a Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 12:49:41 +0530 Subject: [PATCH 11/30] added helm step in jenkins file --- Jenkinsfile | 109 +++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a0eb4ce46..fc92a5a25 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,24 +1,21 @@ pipeline { agent any - tools { - go 'go-1.22.5' + tools { + go 'go-1.22.5' } - environment { - SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') + GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token + } - } - - stages { - - stage('Build'){ - steps{ - sh "go build -o go-web-app" - } + stages { + stage('Build') { + steps { + sh "go build -o go-web-app" + } } stage('Unit Test') { @@ -27,53 +24,67 @@ pipeline { } } - stage('Run SonarQube Analysis') { + stage('Run SonarQube Analysis') { steps { - withSonarQubeEnv('sonar'){ - sh "${SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectKey=gowebapp -Dsonar.projectName=gowebapp" + withSonarQubeEnv('sonar') { + sh "${SCANNER_HOME}/bin/sonar-scanner -Dsonar.projectKey=gowebapp -Dsonar.projectName=gowebapp" } - } } stage('Docker Build & Tag') { - steps { - - script { - withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') - { - sh 'docker build -t vinay7944/go-web-app:v1 .' - } - } - } + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh 'docker build -t vinay7944/go-web-app:v1 .' + } } + } + } - stage('Docker Push image'){ - steps{ - script{ - withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - sh "docker push vinay7944/go-web-app:v1" - } - } - } + stage('Docker Push Image') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh 'docker push vinay7944/go-web-app:v1' + } } + } + } - // stage('Docker deploy to local'){ - // steps{ - // script{ - // withDockerRegistry(credentialsId: 'docker-cred',toolName: 'docker'){ - // sh "docker run -d -p 3000:3000 --name gowebapp vinay7944/go-web-app:latest" - // } - // } - // } - // } - - - } - - post{ - always{ - echo "complete" + stage('Update Helm Chart Tag') { + steps { + script { + // Checkout the repository + checkout scm + + // Update tag in Helm chart + sh ''' + sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml + ''' + + // Configure Git and commit changes + sh ''' + git config --global user.email "abhishek@gmail.com" + git config --global user.name "Abhishek Veeramalla" + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart" + ''' + + // Push changes to the repository + withCredentials([usernamePassword(credentialsId: 'git-cred', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) { + sh ''' + git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/vinnu2251/go-web-app.git + ''' + } + } } } + } + + post { + always { + echo "Complete" + } + } } From 754b09e258cdcc229db85673bfce965713a4deeb Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:03:06 +0530 Subject: [PATCH 12/30] updated jenkins file --- Jenkinsfile | 56 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fc92a5a25..4de3f9e00 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,7 @@ pipeline { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token + DOCKER_CRED = credentials('docker-cred') // Jenkins credential ID for Docker Hub username and password } stages { @@ -32,11 +33,24 @@ pipeline { } } + stage('Get Commit ID') { + steps { + script { + // Get the commit ID + env.COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + } + } + stage('Docker Build & Tag') { steps { script { - withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { - sh 'docker build -t vinay7944/go-web-app:v1 .' + // Build and tag the Docker image with the commit ID + withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { + sh """ + docker build -t ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} . + docker tag ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} ${DOCKER_USERNAME}/go-web-app:latest + """ } } } @@ -45,8 +59,13 @@ pipeline { stage('Docker Push Image') { steps { script { - withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { - sh 'docker push vinay7944/go-web-app:v1' + // Push Docker images with commit ID and latest tag + withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { + sh """ + echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin + docker push ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} + docker push ${DOCKER_USERNAME}/go-web-app:latest + """ } } } @@ -55,28 +74,19 @@ pipeline { stage('Update Helm Chart Tag') { steps { script { - // Checkout the repository - checkout scm - - // Update tag in Helm chart - sh ''' - sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml - ''' + // Update tag in Helm chart with commit ID + sh """ + sed -i 's/tag: .*/tag: "${env.COMMIT_ID}"/' helm/go-web-app-chart/values.yaml + """ // Configure Git and commit changes - sh ''' - git config --global user.email "abhishek@gmail.com" - git config --global user.name "Abhishek Veeramalla" + sh """ + git config --global user.email "vinaychowdarychitturi@gmail.com" + git config --global user.name "vinnu2251" git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart" - ''' - - // Push changes to the repository - withCredentials([usernamePassword(credentialsId: 'git-cred', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) { - sh ''' - git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/vinnu2251/go-web-app.git - ''' - } + git commit -m "Update tag in Helm chart with commit ID ${env.COMMIT_ID}" + git push origin main + """ } } } From 7a7e9982a97d642da619eeb9fb8f721130c78f00 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:07:16 +0530 Subject: [PATCH 13/30] updated jenkins file --- Jenkinsfile | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4de3f9e00..eecf76c3b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,11 +8,20 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token - DOCKER_CRED = credentials('docker-cred') // Jenkins credential ID for Docker Hub username and password + GITHUB_TOKEN = credentials('git-cred') + DOCKER_CRED = credentials('docker-cred') } stages { + stage('Checkout Code') { + steps { + script { + // Checkout the main branch + checkout scm + } + } + } + stage('Build') { steps { sh "go build -o go-web-app" @@ -45,7 +54,6 @@ pipeline { stage('Docker Build & Tag') { steps { script { - // Build and tag the Docker image with the commit ID withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { sh """ docker build -t ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} . @@ -59,7 +67,6 @@ pipeline { stage('Docker Push Image') { steps { script { - // Push Docker images with commit ID and latest tag withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { sh """ echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin From 732c78dd787d3953408ac54b5c46dbd7145cf25e Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:12:54 +0530 Subject: [PATCH 14/30] updated jenkins file --- Jenkinsfile | 54 ++++++++++++----------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eecf76c3b..a6919995d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,19 +9,10 @@ pipeline { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') GITHUB_TOKEN = credentials('git-cred') - DOCKER_CRED = credentials('docker-cred') + DOCKER_USERNAME = 'vinay7944' } stages { - stage('Checkout Code') { - steps { - script { - // Checkout the main branch - checkout scm - } - } - } - stage('Build') { steps { sh "go build -o go-web-app" @@ -42,24 +33,11 @@ pipeline { } } - stage('Get Commit ID') { - steps { - script { - // Get the commit ID - env.COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - } - } - } - stage('Docker Build & Tag') { steps { script { - withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { - sh """ - docker build -t ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} . - docker tag ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} ${DOCKER_USERNAME}/go-web-app:latest - """ - } + COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + sh "docker build -t ${DOCKER_USERNAME}/go-web-app:${COMMIT_ID} ." } } } @@ -70,30 +48,22 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { sh """ echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin - docker push ${DOCKER_USERNAME}/go-web-app:${env.COMMIT_ID} - docker push ${DOCKER_USERNAME}/go-web-app:latest + docker push ${DOCKER_USERNAME}/go-web-app:${COMMIT_ID} """ } } } } - stage('Update Helm Chart Tag') { + stage('Update Helm Chart with Commit ID') { steps { script { - // Update tag in Helm chart with commit ID - sh """ - sed -i 's/tag: .*/tag: "${env.COMMIT_ID}"/' helm/go-web-app-chart/values.yaml - """ - - // Configure Git and commit changes - sh """ - git config --global user.email "vinaychowdarychitturi@gmail.com" - git config --global user.name "vinnu2251" - git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart with commit ID ${env.COMMIT_ID}" - git push origin main - """ + sh "sed -i 's/tag: .*/tag: \"${COMMIT_ID}\"/' helm/go-web-app-chart/values.yaml" + sh "git config --global user.email 'vinaychowdarychitturi@gmail.com'" + sh "git config --global user.name 'vinnu2251'" + sh "git add helm/go-web-app-chart/values.yaml" + sh "git commit -m 'Update tag in Helm chart with commit ID ${COMMIT_ID}'" + sh "git push origin ${env.BRANCH_NAME}" } } } @@ -101,7 +71,7 @@ pipeline { post { always { - echo "Complete" + echo "Pipeline completed" } } } From d226a643f04cb46ee3354534bd8472b85e5e5045 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:19:03 +0530 Subject: [PATCH 15/30] updated jenkins file --- Jenkinsfile | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a6919995d..84309d729 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,14 +2,13 @@ pipeline { agent any tools { - go 'go-1.22.5' + go 'go-1.22.5' } environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') GITHUB_TOKEN = credentials('git-cred') - DOCKER_USERNAME = 'vinay7944' } stages { @@ -37,7 +36,7 @@ pipeline { steps { script { COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - sh "docker build -t ${DOCKER_USERNAME}/go-web-app:${COMMIT_ID} ." + sh 'docker build -t vinay7944/go-web-app:${COMMIT_ID} .' } } } @@ -45,11 +44,8 @@ pipeline { stage('Docker Push Image') { steps { script { - withCredentials([usernamePassword(credentialsId: 'docker-cred', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { - sh """ - echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin - docker push ${DOCKER_USERNAME}/go-web-app:${COMMIT_ID} - """ + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker push vinay7944/go-web-app:${COMMIT_ID}" } } } @@ -58,12 +54,13 @@ pipeline { stage('Update Helm Chart with Commit ID') { steps { script { + sh "git checkout main" // Ensures you are on the main branch sh "sed -i 's/tag: .*/tag: \"${COMMIT_ID}\"/' helm/go-web-app-chart/values.yaml" - sh "git config --global user.email 'vinaychowdarychitturi@gmail.com'" - sh "git config --global user.name 'vinnu2251'" + sh 'git config --global user.email "vinaychowdarychitturi@gmail.com"' + sh 'git config --global user.name "vinnu2251"' sh "git add helm/go-web-app-chart/values.yaml" sh "git commit -m 'Update tag in Helm chart with commit ID ${COMMIT_ID}'" - sh "git push origin ${env.BRANCH_NAME}" + sh "git push origin main" } } } @@ -71,7 +68,7 @@ pipeline { post { always { - echo "Pipeline completed" + echo "Pipeline execution completed." } } } From e1284ac9a964c2169d8eeaf622b64226037758ca Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:21:50 +0530 Subject: [PATCH 16/30] updated jenkins file --- Jenkinsfile | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 84309d729..06e3c356e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any tools { - go 'go-1.22.5' + go 'go-1.22.5' } environment { @@ -12,6 +12,13 @@ pipeline { } stages { + stage('Checkout') { + steps { + // Checkout the code from the GitHub repository + checkout scm + } + } + stage('Build') { steps { sh "go build -o go-web-app" @@ -35,8 +42,13 @@ pipeline { stage('Docker Build & Tag') { steps { script { - COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - sh 'docker build -t vinay7944/go-web-app:${COMMIT_ID} .' + // Get the short commit ID + COMMIT_ID = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() + echo "Commit ID: ${COMMIT_ID}" + // Build and tag the Docker image using the commit ID + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker build -t vinay7944/go-web-app:${COMMIT_ID} ." + } } } } @@ -44,6 +56,7 @@ pipeline { stage('Docker Push Image') { steps { script { + // Push the Docker image to Docker Hub withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { sh "docker push vinay7944/go-web-app:${COMMIT_ID}" } @@ -54,13 +67,17 @@ pipeline { stage('Update Helm Chart with Commit ID') { steps { script { - sh "git checkout main" // Ensures you are on the main branch + // Update the Helm chart values with the new Docker image tag (commit ID) sh "sed -i 's/tag: .*/tag: \"${COMMIT_ID}\"/' helm/go-web-app-chart/values.yaml" - sh 'git config --global user.email "vinaychowdarychitturi@gmail.com"' - sh 'git config --global user.name "vinnu2251"' - sh "git add helm/go-web-app-chart/values.yaml" - sh "git commit -m 'Update tag in Helm chart with commit ID ${COMMIT_ID}'" - sh "git push origin main" + + // Commit and push the changes to the Helm chart + sh """ + git config --global user.email "vinaychowdarychitturi@gmail.com" + git config --global user.name "vinnu2251" + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart with commit ID ${COMMIT_ID}" + git push origin main + """ } } } @@ -68,7 +85,7 @@ pipeline { post { always { - echo "Pipeline execution completed." + echo "Pipeline complete." } } } From d6cb17676ede2eefd84834389965d88f724b7b49 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:24:47 +0530 Subject: [PATCH 17/30] updated jenkins file --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 06e3c356e..cd504e581 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,8 +14,9 @@ pipeline { stages { stage('Checkout') { steps { - // Checkout the code from the GitHub repository + // Checkout the code from the GitHub repository and switch to the main branch checkout scm + sh 'git checkout main' } } From 4a165432754d7eedd5786b7b676ab47247eb9a06 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:29:14 +0530 Subject: [PATCH 18/30] updated jenkins file --- Jenkinsfile | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cd504e581..80a0fd1e9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,20 +9,25 @@ pipeline { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') GITHUB_TOKEN = credentials('git-cred') + DOCKER_CRED = credentials('docker-cred') + COMMIT_ID = "" } stages { - stage('Checkout') { + stage('Checkout Code') { steps { - // Checkout the code from the GitHub repository and switch to the main branch - checkout scm - sh 'git checkout main' + checkout([$class: 'GitSCM', branches: [[name: 'main']], + userRemoteConfigs: [[url: 'git@github.com:vinnu2251/go-web-app.git', + credentialsId: 'git-ssh-cred']]]) } } stage('Build') { steps { - sh "go build -o go-web-app" + script { + COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + sh "go build -o go-web-app" + } } } @@ -43,12 +48,9 @@ pipeline { stage('Docker Build & Tag') { steps { script { - // Get the short commit ID - COMMIT_ID = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() - echo "Commit ID: ${COMMIT_ID}" - // Build and tag the Docker image using the commit ID - withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + withDockerRegistry(credentialsId: 'docker-cred') { sh "docker build -t vinay7944/go-web-app:${COMMIT_ID} ." + sh "docker tag vinay7944/go-web-app:${COMMIT_ID} vinay7944/go-web-app:latest" } } } @@ -57,9 +59,9 @@ pipeline { stage('Docker Push Image') { steps { script { - // Push the Docker image to Docker Hub - withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + withDockerRegistry(credentialsId: 'docker-cred') { sh "docker push vinay7944/go-web-app:${COMMIT_ID}" + sh "docker push vinay7944/go-web-app:latest" } } } @@ -68,17 +70,14 @@ pipeline { stage('Update Helm Chart with Commit ID') { steps { script { - // Update the Helm chart values with the new Docker image tag (commit ID) sh "sed -i 's/tag: .*/tag: \"${COMMIT_ID}\"/' helm/go-web-app-chart/values.yaml" - - // Commit and push the changes to the Helm chart - sh """ + sh ''' git config --global user.email "vinaychowdarychitturi@gmail.com" git config --global user.name "vinnu2251" git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart with commit ID ${COMMIT_ID}" git push origin main - """ + ''' } } } @@ -86,7 +85,7 @@ pipeline { post { always { - echo "Pipeline complete." + echo "Pipeline completed" } } } From 68418bdf3b95fb44628ec71115347a0ef2cd6a96 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:38:36 +0530 Subject: [PATCH 19/30] updated jenkins file --- Jenkinsfile | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 80a0fd1e9..22c9e50d1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,26 +8,31 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_TOKEN = credentials('git-cred') - DOCKER_CRED = credentials('docker-cred') - COMMIT_ID = "" + GITHUB_TOKEN = credentials('git-cred') // Your GitHub token + DOCKER_CREDENTIALS = credentials('docker-cred') // Docker credentials } stages { stage('Checkout Code') { steps { - checkout([$class: 'GitSCM', branches: [[name: 'main']], - userRemoteConfigs: [[url: 'git@github.com:vinnu2251/go-web-app.git', - credentialsId: 'git-ssh-cred']]]) + script { + // Use the GitHub token for authentication + withCredentials([string(credentialsId: 'git-cred', variable: 'GITHUB_TOKEN')]) { + sh ''' + git config --global url."https://github.com/".insteadOf git@github.com: + git config --global user.email "vinaychowdarychitturi@gmail.com" + git config --global user.name "vinnu2251" + git clone https://github.com/vinnu2251/go-web-app.git + cd go-web-app + ''' + } + } } } stage('Build') { steps { - script { - COMMIT_ID = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - sh "go build -o go-web-app" - } + sh "go build -o go-web-app" } } @@ -48,9 +53,9 @@ pipeline { stage('Docker Build & Tag') { steps { script { + def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() withDockerRegistry(credentialsId: 'docker-cred') { - sh "docker build -t vinay7944/go-web-app:${COMMIT_ID} ." - sh "docker tag vinay7944/go-web-app:${COMMIT_ID} vinay7944/go-web-app:latest" + sh "docker build -t vinay7944/go-web-app:${commitId} ." } } } @@ -59,9 +64,9 @@ pipeline { stage('Docker Push Image') { steps { script { + def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() withDockerRegistry(credentialsId: 'docker-cred') { - sh "docker push vinay7944/go-web-app:${COMMIT_ID}" - sh "docker push vinay7944/go-web-app:latest" + sh "docker push vinay7944/go-web-app:${commitId}" } } } @@ -70,14 +75,13 @@ pipeline { stage('Update Helm Chart with Commit ID') { steps { script { - sh "sed -i 's/tag: .*/tag: \"${COMMIT_ID}\"/' helm/go-web-app-chart/values.yaml" - sh ''' - git config --global user.email "vinaychowdarychitturi@gmail.com" - git config --global user.name "vinnu2251" - git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart with commit ID ${COMMIT_ID}" - git push origin main - ''' + def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + sh """ + sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart with commit ID ${commitId}" + git push origin main + """ } } } From c68b26bb3e4d38c9fe6f43f486a52bc8edbfa38e Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:43:23 +0530 Subject: [PATCH 20/30] updated jenkins file --- Jenkinsfile | 63 ++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 22c9e50d1..2589c8538 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,28 +8,10 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_TOKEN = credentials('git-cred') // Your GitHub token - DOCKER_CREDENTIALS = credentials('docker-cred') // Docker credentials + GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token } stages { - stage('Checkout Code') { - steps { - script { - // Use the GitHub token for authentication - withCredentials([string(credentialsId: 'git-cred', variable: 'GITHUB_TOKEN')]) { - sh ''' - git config --global url."https://github.com/".insteadOf git@github.com: - git config --global user.email "vinaychowdarychitturi@gmail.com" - git config --global user.name "vinnu2251" - git clone https://github.com/vinnu2251/go-web-app.git - cd go-web-app - ''' - } - } - } - } - stage('Build') { steps { sh "go build -o go-web-app" @@ -53,9 +35,8 @@ pipeline { stage('Docker Build & Tag') { steps { script { - def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - withDockerRegistry(credentialsId: 'docker-cred') { - sh "docker build -t vinay7944/go-web-app:${commitId} ." + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh 'docker build -t vinay7944/go-web-app:v1 .' } } } @@ -64,24 +45,38 @@ pipeline { stage('Docker Push Image') { steps { script { - def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - withDockerRegistry(credentialsId: 'docker-cred') { - sh "docker push vinay7944/go-web-app:${commitId}" + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh 'docker push vinay7944/go-web-app:v1' } } } } - stage('Update Helm Chart with Commit ID') { + stage('Update Helm Chart Tag') { steps { script { - def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - sh """ - sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml - git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart with commit ID ${commitId}" - git push origin main - """ + // Checkout the repository + checkout scm + + // Update tag in Helm chart + sh ''' + sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml + ''' + + // Configure Git and commit changes + sh ''' + git config --global user.email "abhishek@gmail.com" + git config --global user.name "Abhishek Veeramalla" + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart" + ''' + + // Push changes to the repository + withCredentials([usernamePassword(credentialsId: 'git-cred', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) { + sh ''' + git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/your-repo/your-repo-name.git + ''' + } } } } @@ -89,7 +84,7 @@ pipeline { post { always { - echo "Pipeline completed" + echo "Complete" } } } From 12f4e828407d0c16ef3e5e954734e1cf9ca9682d Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:47:37 +0530 Subject: [PATCH 21/30] updated jenkins file --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2589c8538..d8f6de3b0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -65,8 +65,8 @@ pipeline { // Configure Git and commit changes sh ''' - git config --global user.email "abhishek@gmail.com" - git config --global user.name "Abhishek Veeramalla" + git config --global user.email "vinaychowdarychitturi@gmail.com" + git config --global user.name "vinay chitturi" git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart" ''' @@ -74,7 +74,7 @@ pipeline { // Push changes to the repository withCredentials([usernamePassword(credentialsId: 'git-cred', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) { sh ''' - git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/your-repo/your-repo-name.git + git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/vinnu2251/go-web-app.git ''' } } From 08f978b2d03cd8f11be587154f1cb74ddbb2f115 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:50:40 +0530 Subject: [PATCH 22/30] updated jenkins file --- Jenkinsfile | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d8f6de3b0..718dacfa0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,9 +9,25 @@ pipeline { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token + DOCKER_CRED = credentials('docker-cred') // Docker credentials } stages { + stage('Checkout Code') { + steps { + script { + // Checkout the repository + checkout scm + + // Configure Git for Jenkins + sh """ + git config --global user.email "vinaychowdarychitturi@gmail.com" + git config --global user.name "vinay chitturi" + """ + } + } + } + stage('Build') { steps { sh "go build -o go-web-app" @@ -55,28 +71,20 @@ pipeline { stage('Update Helm Chart Tag') { steps { script { - // Checkout the repository - checkout scm + // Get the current branch name + def branchName = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() // Update tag in Helm chart - sh ''' + sh """ sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml - ''' + """ - // Configure Git and commit changes - sh ''' - git config --global user.email "vinaychowdarychitturi@gmail.com" - git config --global user.name "vinay chitturi" + // Add, commit, and push changes + sh """ git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart" - ''' - - // Push changes to the repository - withCredentials([usernamePassword(credentialsId: 'git-cred', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) { - sh ''' - git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/vinnu2251/go-web-app.git - ''' - } + git push origin ${branchName} + """ } } } From 60a56c842be85d2c3fdc43701292b1a9b5296a22 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 13:57:59 +0530 Subject: [PATCH 23/30] updated jenkins file --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 718dacfa0..02f10c945 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,6 +24,10 @@ pipeline { git config --global user.email "vinaychowdarychitturi@gmail.com" git config --global user.name "vinay chitturi" """ + + // Debugging steps + sh 'git status' // Show current status of the working directory + sh 'git branch -a' // List all branches } } } From 25c2877dce40af2ed7ce868e226cc58494084411 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 14:03:28 +0530 Subject: [PATCH 24/30] updated jenkins file --- Jenkinsfile | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 02f10c945..b4d5e0dd6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -77,17 +77,27 @@ pipeline { script { // Get the current branch name def branchName = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() + echo "Current branch: ${branchName}" - // Update tag in Helm chart + // Debugging steps for updating Helm chart sh """ - sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml + echo "Current directory:" + pwd + echo "Listing files:" + ls -l + echo "Checking Helm chart values:" + cat helm/go-web-app-chart/values.yaml + echo "Updating tag in Helm chart" + sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml + echo "Updated Helm chart values:" + cat helm/go-web-app-chart/values.yaml """ // Add, commit, and push changes sh """ - git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart" - git push origin ${branchName} + git add helm/go-web-app-chart/values.yaml + git commit -m "Update tag in Helm chart" + git push origin ${branchName} """ } } @@ -96,7 +106,8 @@ pipeline { post { always { - echo "Complete" + echo "Pipeline complete" + cleanWs() // Clean workspace after the build } } } From b83a971ae78a39137397856923f982aae5f47c86 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 14:22:37 +0530 Subject: [PATCH 25/30] updated jenkins file --- Jenkinsfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b4d5e0dd6..7f34172ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,6 +75,10 @@ pipeline { stage('Update Helm Chart Tag') { steps { script { + // Get the commit ID + def commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + echo "Current commit ID: ${commitId}" + // Get the current branch name def branchName = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() echo "Current branch: ${branchName}" @@ -88,7 +92,7 @@ pipeline { echo "Checking Helm chart values:" cat helm/go-web-app-chart/values.yaml echo "Updating tag in Helm chart" - sed -i 's/tag: .*/tag: "${BUILD_NUMBER}"/' helm/go-web-app-chart/values.yaml + sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml echo "Updated Helm chart values:" cat helm/go-web-app-chart/values.yaml """ @@ -96,7 +100,7 @@ pipeline { // Add, commit, and push changes sh """ git add helm/go-web-app-chart/values.yaml - git commit -m "Update tag in Helm chart" + git commit -m "Update tag in Helm chart with commit ID ${commitId}" git push origin ${branchName} """ } From 2df3d7e0122f84dc1cd6138eee422ed00bf37ca6 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 17:06:13 +0530 Subject: [PATCH 26/30] updated jenkins file --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7f34172ec..493876c55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token + GITHUB_SSH_KEY = credentials('gitssh-cred') // Jenkins SSH key ID for GitHub DOCKER_CRED = credentials('docker-cred') // Docker credentials } @@ -23,6 +23,7 @@ pipeline { sh """ git config --global user.email "vinaychowdarychitturi@gmail.com" git config --global user.name "vinay chitturi" + git remote set-url origin git@github.com:vinnu2251/go-web-app.git """ // Debugging steps @@ -101,7 +102,7 @@ pipeline { sh """ git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart with commit ID ${commitId}" - git push origin ${branchName} + git push origin HEAD """ } } From 5d18f783e9a7356abb2fd8ecf1c69e375c998443 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 17:31:03 +0530 Subject: [PATCH 27/30] updated jenkins file --- Jenkinsfile | 36 +++++++++++-------------------- helm/go-web-app-chart/values.yaml | 2 +- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 493876c55..b108b591f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_SSH_KEY = credentials('gitssh-cred') // Jenkins SSH key ID for GitHub + GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token DOCKER_CRED = credentials('docker-cred') // Docker credentials } @@ -16,19 +16,20 @@ pipeline { stage('Checkout Code') { steps { script { - // Checkout the repository - checkout scm + // Use HTTPS URL with GitHub token for authentication + checkout([$class: 'GitSCM', + branches: [[name: '*/main']], // Replace 'main' with your branch + userRemoteConfigs: [[ + url: 'https://github.com/vinnu2251/go-web-app.git', + credentialsId: 'git-cred' + ]] + ]) // Configure Git for Jenkins sh """ git config --global user.email "vinaychowdarychitturi@gmail.com" git config --global user.name "vinay chitturi" - git remote set-url origin git@github.com:vinnu2251/go-web-app.git """ - - // Debugging steps - sh 'git status' // Show current status of the working directory - sh 'git branch -a' // List all branches } } } @@ -84,26 +85,15 @@ pipeline { def branchName = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() echo "Current branch: ${branchName}" - // Debugging steps for updating Helm chart + // Update the Helm chart with the new tag sh """ - echo "Current directory:" - pwd - echo "Listing files:" - ls -l - echo "Checking Helm chart values:" - cat helm/go-web-app-chart/values.yaml - echo "Updating tag in Helm chart" sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml - echo "Updated Helm chart values:" - cat helm/go-web-app-chart/values.yaml - """ - - // Add, commit, and push changes - sh """ git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart with commit ID ${commitId}" - git push origin HEAD """ + + // Push changes using the Git Push Plugin + gitPush branch: branchName, credentialsId: 'git-cred', pushTags: true } } } diff --git a/helm/go-web-app-chart/values.yaml b/helm/go-web-app-chart/values.yaml index d54f5546b..62c07c39c 100644 --- a/helm/go-web-app-chart/values.yaml +++ b/helm/go-web-app-chart/values.yaml @@ -5,7 +5,7 @@ replicaCount: 1 image: - repository: abhishekf5/go-web-app + repository: vinay7944/go-web-app pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "v1" From 4c05e100dfcf0336f06fe0519bfd62e1fcefc956 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 17:39:13 +0530 Subject: [PATCH 28/30] updated jenkins file --- Jenkinsfile | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b108b591f..1cf6a80ef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { SCANNER_HOME = tool 'sonar-scanner' SONAR_TOKEN = credentials('sonar-cred') - GITHUB_TOKEN = credentials('git-cred') // Jenkins credential ID for the GitHub token + GITHUB_TOKEN = credentials('git-cred') // GitHub token DOCKER_CRED = credentials('docker-cred') // Docker credentials } @@ -16,17 +16,12 @@ pipeline { stage('Checkout Code') { steps { script { - // Use HTTPS URL with GitHub token for authentication - checkout([$class: 'GitSCM', - branches: [[name: '*/main']], // Replace 'main' with your branch - userRemoteConfigs: [[ - url: 'https://github.com/vinnu2251/go-web-app.git', - credentialsId: 'git-cred' - ]] - ]) + // Checkout the repository + checkout scm - // Configure Git for Jenkins + // Set the remote URL to HTTPS and use the GitHub token sh """ + git remote set-url origin https://vinnu2251:${GITHUB_TOKEN}@github.com/vinnu2251/go-web-app.git git config --global user.email "vinaychowdarychitturi@gmail.com" git config --global user.name "vinay chitturi" """ @@ -88,12 +83,14 @@ pipeline { // Update the Helm chart with the new tag sh """ sed -i 's/tag: .*/tag: "${commitId}"/' helm/go-web-app-chart/values.yaml + """ + + // Add, commit, and push the changes using the GitHub token + sh """ git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart with commit ID ${commitId}" + git push origin HEAD:${branchName} """ - - // Push changes using the Git Push Plugin - gitPush branch: branchName, credentialsId: 'git-cred', pushTags: true } } } From 820de590882fd39bb0d7a4f332179ff690e6518a Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 17:47:52 +0530 Subject: [PATCH 29/30] updated jenkins file --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1cf6a80ef..43d4efda7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -89,7 +89,7 @@ pipeline { sh """ git add helm/go-web-app-chart/values.yaml git commit -m "Update tag in Helm chart with commit ID ${commitId}" - git push origin HEAD:${branchName} + git push https://vinnu2251:${GITHUB_TOKEN}@github.com/vinnu2251/go-web-app.git HEAD:refs/heads/${branchName} """ } } From 748975d33402d434042ed412ff08ef522aceef43 Mon Sep 17 00:00:00 2001 From: vinay chitturi Date: Fri, 16 Aug 2024 12:18:57 +0000 Subject: [PATCH 30/30] Update tag in Helm chart with commit ID 820de59 --- helm/go-web-app-chart/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/go-web-app-chart/values.yaml b/helm/go-web-app-chart/values.yaml index 62c07c39c..6f079f3d4 100644 --- a/helm/go-web-app-chart/values.yaml +++ b/helm/go-web-app-chart/values.yaml @@ -8,7 +8,7 @@ image: repository: vinay7944/go-web-app pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: "v1" + tag: "820de59" ingress: enabled: false