-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
76 lines (65 loc) · 2.82 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pipeline {
agent any
environment {
GIT_REPO = 'https://github.com/AbdelrhmanAli123/microservices-devops-task.git'
GIT_BRANCH = 'main'
SCANNER_HOME = tool 'sonarqube';
IMAGE_NAME = 'abdelrhmandevops/microservices-task'
CLUSTER_NAME = 'my-eks'
REGION = 'us-east-2'
}
// use this stage if your repo is private otherwise don't declare this stage
stages {
stage("Code Checkout from Github") {
steps {
git credentialsId:'github_cred', url: '${GIT_REPO}', branch: '${GIT_BRANCH}'
}
}
// ----------------------------------------------------
// this for code quelity but we don't need it here
// ----------------------------------------------------
// stage('SonarQube analysis') {
// steps {
// script {
// def scannerHome = tool 'sonarqube' // sonarqube global tool
// withSonarQubeEnv('sonarqube') { // and this is the sonarqube scanner that we passed the token in to authenticate jenkins into sonarqube server
// sh """
// ${scannerHome}/bin/sonar-scanner \
// -Dsonar.projectKey=micro-task \
// -Dsonar.projectName=micro-task \
// -Dsonar.projectVersion=1.0 \
// -Dsonar.sources=src/
// """
// }
// }
// }
// }
stage('Build Docker Image and push it to DockerHub') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub_cred', passwordVariable: 'password', usernameVariable: 'username')]) {
sh """
docker build . -t ${IMAGE_NAME}:${BUILD_NUMBER}
docker login -u ${username} -p ${password}
docker push ${IMAGE_NAME}:${BUILD_NUMBER}
"""
}
}
}
stage('deploy the nodejs via helm'){
steps{
script {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY',
credentialsId: 'aws_cred'
]]) {
sh "aws eks update-kubeconfig --region ${REGION} --name %{CLUSTER_NAME} || true
sh "helm upgrade --install --force micro-app ./helm_chart --set appImage=${IMAGE_NAME}:${BUILD_NUMBER}"
sh "Docker rmi --force ${IMAGE_NAME}:${BUILD_NUMBER} || true "
}
}
}
}
}
}