-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
68 lines (46 loc) · 1.9 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
pipeline {
agent { label "jenkins_slave"}
parameters {
choice(name: 'ENV', choices: ['build', 'deploy'])
}
stages {
stage('build') {
steps {
echo 'build'
script{
if (params.ENV == "build") {
withCredentials([usernamePassword(credentialsId: 'mariam-dockerHub', usernameVariable: 'USERNAME_ITI', passwordVariable: 'PASSWORD_ITI')]) {
sh '''
docker login -u ${USERNAME_ITI} -p ${PASSWORD_ITI}
docker build -t mariamkasssab/iti_project:v${BUILD_NUMBER} .
docker push mariamkasssab/iti_project:v${BUILD_NUMBER}
echo ${BUILD_NUMBER} > ../build.txt
'''
}
}
else {
echo "user choosed ${params.ENV}"
}
}
}
}
stage('deploy') {
steps {
echo 'deploy'
script {
if (params.ENV == "deploy") {
withCredentials([file(credentialsId: 'mariam-kubeconfig', variable: 'KUBECONFIG_ITI')]) {
sh '''
export BUILD_NUMBER=$(cat ../build.txt)
mv Deployment/deploy.yaml Deployment/deploy.yaml.tmp
cat Deployment/deploy.yaml.tmp | envsubst > Deployment/deploy.yaml
rm -f Deployment/deploy.yaml.tmp
kubectl apply -f Deployment --kubeconfig ${KUBECONFIG_ITI} -n app
'''
}
}
}
}
}
}
}