From 048b2d38d9979817cdd99a07149dc40c37e381a6 Mon Sep 17 00:00:00 2001 From: Aahil Date: Sun, 19 May 2024 20:42:22 +0100 Subject: [PATCH] Update Jenkinsfile --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ++++ Jenkinsfile | 56 ++++++++++++++++++++++++++++++++++++ sonar-project.properties | 15 ++++++++++ 4 files changed, 77 insertions(+) create mode 100644 .scannerwork/.sonar_lock create mode 100644 .scannerwork/report-task.txt create mode 100644 Jenkinsfile create mode 100644 sonar-project.properties diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock new file mode 100644 index 0000000..e69de29 diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt new file mode 100644 index 0000000..dca1edb --- /dev/null +++ b/.scannerwork/report-task.txt @@ -0,0 +1,6 @@ +projectKey=Test-project +serverUrl=http://localhost:9000 +serverVersion=10.5.1.90531 +dashboardUrl=http://localhost:9000/dashboard?id=Test-project +ceTaskId=6f4e4d31-6df9-46c6-8095-df8e3dfd5321 +ceTaskUrl=http://localhost:9000/api/ce/task?id=6f4e4d31-6df9-46c6-8095-df8e3dfd5321 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1ac5c91 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,56 @@ +pipeline { + agent any + + stages { + stage('Configure') { + steps { + checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/Aahil13/Word-counter']]) + } + } + stage('Building image') { + steps { + sh 'docker build -t word-counter .' + } + } + + stage('Pushing to ECR') { + steps { + withAWS(credentials: 'AWS-CREDS', region: 'us-east-1') { + sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 313382416572.dkr.ecr.us-east-1.amazonaws.com' + sh 'docker tag word-counter:latest 313382416572.dkr.ecr.us-east-1.amazonaws.com/jenkins:latest' + sh 'docker push 313382416572.dkr.ecr.us-east-1.amazonaws.com/jenkins:latest' + } + } + } + + stage('K8S Deploy') { + steps { + script { + withAWS(credentials: 'AWS-CREDS', region: 'us-east-1') { + sh 'aws eks update-kubeconfig --name test-cluster --region us-east-1' + sh 'kubectl apply -f EKS-Deployment.yaml' + } + } + } + } + + stage('Get Service URL') { + steps { + script { + def serviceUrl = "" + // Wait for the LoadBalancer IP to be assigned + timeout(time: 5, unit: 'MINUTES') { + while(serviceUrl == "") { + serviceUrl = sh(script: "kubectl get svc word-counter-service -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'", returnStdout: true).trim() + if(serviceUrl == "") { + echo "Waiting for the LoadBalancer IP..." + sleep 10 + } + } + } + echo "Service URL: http://${serviceUrl}" + } + } + } + } +} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..e94dfc5 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,15 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=Test-project + +# --- optional properties --- + +# defaults to project key +#sonar.projectName=My project +# defaults to 'not provided' +#sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Defaults to . +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +sonar.sourceEncoding=UTF-8 \ No newline at end of file