forked from crawlab-team/crawlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
70 lines (69 loc) · 2.21 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
pipeline {
agent {
node {
label 'crawlab'
}
}
stages {
stage('Setup') {
steps {
echo "Running Setup..."
script {
if (env.GIT_BRANCH == 'develop') {
env.TAG = 'develop'
env.DOCKERFILE = 'Dockerfile.local'
} else if (env.GIT_BRANCH == 'master') {
env.TAG = 'master'
env.DOCKERFILE = 'Dockerfile.local'
} else if (env.GIT_BRANCH == 'frontend') {
env.TAG = 'frontend-alpine'
env.DOCKERFILE = 'docker/Dockerfile.frontend.alpine'
} else if (env.GIT_BRANCH == 'backend-master') {
env.TAG = 'master-alpine'
env.DOCKERFILE = 'docker/Dockerfile.master.alpine'
} else if (env.GIT_BRANCH == 'backend-worker') {
env.TAG = 'worker-alpine'
env.DOCKERFILE = 'docker/Dockerfile.worker.alpine'
}
}
}
}
stage('Build') {
steps {
echo "Building..."
sh """
docker build -t tikazyq/crawlab:${ENV:TAG} -f ${ENV:DOCKERFILE} .
"""
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
sh """
if [[ ${ENV:GIT_BRANCH} = master ]] || [[ ${ENV:GIT_BRANCH} = develop ]]; then
# 重启docker compose
cd ./jenkins/${ENV:GIT_BRANCH}
docker-compose stop | true
docker-compose up -d
else
# 发布到Dockerhub
docker push tikazyq/crawlab:${ENV:TAG}
fi
"""
}
}
stage('Cleanup') {
steps {
echo 'Cleanup...'
sh """
docker image prune -f
"""
}
}
}
}