-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
85 lines (73 loc) · 3.03 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
def buildDockerfile(folder_name, version) {
echo "Building Dockerfile at ${folder_name}/Dockerfile for ${folder_name}... with version ${version}"
// Build Docker image using the specified Dockerfile
script {
def completeImageName = "${env.DOCKER_HUB_REPO}/${folder_name}" // Concatenate repo with image name
def image = docker.build(completeImageName, "-f ${folder_name}/Dockerfile ./${folder_name}")
echo "Prepare to release newer version ${completeImageName}:${version}"
docker.withRegistry('https://registry.linto.ai', env.DOCKER_HUB_CRED) {
if (version == 'latest-unstable') {
image.push('latest-unstable')
} else {
image.push('latest')
image.push(version)
}
}
}
}
// For linto studio, the folder name have the same name of the docker image
def performBuildForFile(changedFiles, version) {
if (changedFiles.contains('studio-api')) {
echo 'Files in studio-api path are modified. Running specific build steps for studio-api...'
buildDockerfile('studio-api', version)
}
if (changedFiles.contains('studio-frontend')) {
echo 'Files in studio-frontend path are modified. Running specific build steps for studio-frontend...'
buildDockerfile('studio-frontend', version)
}
if (changedFiles.contains('studio-websocket')) {
echo 'Files in studio-websocket path are modified. Running specific build steps for studio-websocket...'
buildDockerfile('studio-websocket', version)
}
if (changedFiles.contains('studio-dashboard')) {
echo 'Files in studio-dashboard path are modified. Running specific build steps for studio-dashboard...'
buildDockerfile('studio-dashboard', version)
}
}
pipeline {
agent any
environment {
DOCKER_HUB_REPO = "linto-studio"
DOCKER_HUB_CRED = 'harbor-jenkins-robot'
}
stages {
stage('Docker build for master branch') {
when {
branch 'master'
}
steps {
echo 'Publishing latest'
script {
def changedFiles = sh(returnStdout: true, script: 'git diff --name-only HEAD^ HEAD').trim()
version = sh(
returnStdout: true,
script: "awk -v RS='' '/#/ {print; exit}' RELEASE.md | head -1 | sed 's/#//' | sed 's/ //'"
).trim()
performBuildForFile(changedFiles, version)
}
}
}
stage('Docker build for next (unstable) branch') {
when {
branch 'next'
}
steps {
echo 'Publishing unstable'
script {
def changedFiles = sh(returnStdout: true, script: 'git diff --name-only HEAD^ HEAD').trim()
performBuildForFile(changedFiles, 'latest-unstable')
}
}
}
}
}