-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
83 lines (76 loc) · 2.39 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
#!/groovy
pipeline{
agent any
environment {
REPOSITORY = "https://github.com/nju-softeng/dop-web.git"
SERVICE_DIR="./"
DOCKER_REGISTRY_HOST = "172.29.7.157:85"
DOCKER_REGISTRY = "172.29.7.157:85/dop/dop-web"
}
stages {
stage('pull code') {
steps {
echo "fetching code from git:${REPOSITORY}"
deleteDir()
//git "${REPOSITORY}"
checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: "${REPOSITORY}"]]])
script {
time = sh(returnStdout: true, script: 'date "+%Y%m%d%H%M"').trim()
git_version = sh(returnStdout: true, script: 'git log -1 --pretty=format:"%h"').trim()
build_tag = time+git_version
}
}
}
stage('build') {
steps {
echo "building"
dir(SERVICE_DIR){
sh "ls -l"
sh "yarn install"
sh "yarn build"
}
}
}
stage('build image') {
steps {
echo "building image"
echo "image tag : ${build_tag}"
dir(SERVICE_DIR){
sh "ls -l"
sh "docker build -t ${DOCKER_REGISTRY}:${build_tag} --network host ."
}
}
}
stage('push docker') {
steps {
echo "pushing image"
dir(SERVICE_DIR){
sh "ls -l"
withCredentials([usernamePassword(credentialsId: 'docker_registry', passwordVariable: 'password', usernameVariable: 'username')]) {
sh "docker login -u ${username} -p ${password} ${DOCKER_REGISTRY_HOST}"
sh "docker push ${DOCKER_REGISTRY}:${build_tag}"
}
}
}
}
stage('update yaml') {
steps{
echo "changing yaml image tag"
dir(SERVICE_DIR){
sh "ls -l"
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s.yaml"
sh "cat k8s.yaml"
}
}
}
stage('deploy') {
steps {
echo "deploying"
dir(SERVICE_DIR){
sh "ls -l"
sh "kubectl apply -f k8s.yaml"
}
}
}
}
}