-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
100 lines (92 loc) · 3.62 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
pipeline {
agent {
label 'docker-agent'
}
environment {
DOCKERHUB_CREDENTIALS= credentials('dockerhubcredentials')
GITHUB_CREDENTIALS= credentials('githubcredentials')
}
stages {
stage('Initialize Docker') {
steps {
script {
def dockerHome = tool 'docker'
env.PATH = "${dockerHome}/bin:${env.PATH}"
}
}
}
stage('Get Version') {
steps {
script {
def backend = readJSON file: 'backend/package.json'
env.BACKEND_VERSION = backend.version
echo "Backend Version from package.json: ${env.BACKEND_VERSION}"
def frontend = readJSON file: 'frontend/package.json'
env.FRONTEND_VERSION = frontend.version
echo "Frontend Version from package.json: ${env.FRONTEND_VERSION}"
}
}
}
stage('Login to Docker Hub') {
steps{
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
echo 'Login Completed'
}
}
stage('Build') {
parallel {
stage('Build Backend') {
steps {
script {
dir('backend') {
sh "docker build -t programmingninjas/argolink-backend:${BACKEND_VERSION} ."
sh 'docker push programmingninjas/argolink-backend:${BACKEND_VERSION}'
}
}
}
}
stage('Build Frontend') {
steps {
script {
dir('frontend') {
sh "docker build -t programmingninjas/argolink-frontend:${FRONTEND_VERSION} ."
sh 'docker push programmingninjas/argolink-frontend:${FRONTEND_VERSION}'
}
}
}
}
}
}
stage('Deploy') {
steps {
script {
sh 'git config --global credential.helper store'
sh "echo \"https://${GITHUB_CREDENTIALS_USR}:${GITHUB_CREDENTIALS_PSW}@github.com\" > ~/.git-credentials"
sh 'git config --global user.email "[email protected]"'
sh 'git config --global user.name "Ayan Khan"'
sh "git clone https://github.com/programmingninjas/quectoCharts.git"
dir('quectoCharts/quectoCharts'){
sh "ls"
sh "sed -i 's/^version: .*/version: ${BACKEND_VERSION}/' Chart.yaml"
sh "sed -i 's/^ tag: .*/ tag: ${BACKEND_VERSION}/' values.yaml"
sh "git add Chart.yaml"
sh "git add values.yaml"
sh "git commit -m 'Update Helm chart version to ${BACKEND_VERSION}'"
sh "git push origin main"
}
}
}
}
}
post {
always {
sh 'docker logout'
}
success {
echo 'Deployment successful!'
}
failure {
echo 'Deployment failed!'
}
}
}