-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathJenkinsfile
181 lines (119 loc) · 4.15 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
pipeline {
agent {
kubernetes {
yaml """
kind: Pod
spec:
containers:
- name: smarttech-ci
image: python:slim
command:
- cat
tty: true
- name: smarttech-cd
image: python:slim
command:
- cat
tty: true
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- sleep
args:
- 9999999
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: docker-credentials
items:
- key: .dockerconfigjson
path: config.json
"""
}
}
stages {
stage('Build with Kaniko') {
steps {
script {
container('smarttech-ci') {
withCredentials([
string(credentialsId: 'REPO_CREDS_ID', variable: 'REPO_PRIVATE_TOKEN'),
])
{
sh '''
echo "Login to CI Repo..."
echo ${BUILD_NUMBER}
echo $REPO_PRIVATE_TOKEN
apt update -y && apt install -y git
git clone https://oauth2:${REPO_PRIVATE_TOKEN}@github.com/ashaik65/jenkins-kaniko.git
ls
'''
}
}
}
container(name: 'kaniko', shell: '/busybox/sh') {
sh '''#!/busybox/sh
ls
pwd
cd jenkins-kaniko/jenkins-k8-cicd-main
ls
/kaniko/executor --context `pwd` --destination ashaik65/kaniko:${BUILD_NUMBER}
'''
}
}
}
stage('Deploy With Helm') {
steps {
script {
container('smarttech-cd') {
withCredentials([
string(credentialsId: 'HELM_REPO_CREDS_ID', variable: 'HELM_REPO_PRIVATE_TOKEN'),
string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID'),
string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'),
string(credentialsId: 'AWS_DEFAULT_REGION', variable: 'AWS_DEFAULT_REGION'),
])
{
sh '''
echo "Login to CD Helm Repo..."
echo ${AWS_ACCESS_KEY_ID}
echo ${AWS_SECRET_ACCESS_KEY}
echo ${AWS_DEFAULT_REGION}
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
echo ${BUILD_NUMBER}
echo $HELM_REPO_PRIVATE_TOKEN
apt update -y && apt install -y git curl zip unzip sudo
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
aws eks update-kubeconfig --name demo-cluster --region ${AWS_DEFAULT_REGION}
echo "Kubectl Installation"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
kubectl get nodes
echo "Helm Installation"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
git clone https://oauth2:${HELM_REPO_PRIVATE_TOKEN}@github.com/ashaik65/k8-helm.git
ls
cd k8-helm/k8-helm-main
helm upgrade --install hello -f charts/hello/values.yaml --set image.repository=ashaik65/kaniko:${BUILD_NUMBER} --namespace hello charts/hello/ --atomic --timeout 1m25s --cleanup-on-fail
'''
}
}
}
}
}
}
}