-
Notifications
You must be signed in to change notification settings - Fork 18
/
Jenkinsfile
103 lines (91 loc) · 3.5 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
#!groovy
// http://stackoverflow.com/questions/37425064/how-to-use-environment-variables-in-a-groovy-function-using-a-jenkinsfile
import groovy.transform.Field
@Field buildParams = [
"REBUILD": "false",
"LEAVE_CONTAINER": "0",
"ALWAYS_PRINT_LOGS": "0",
"REDIS_MONITOR_LOGS": "0",
"WATCHDOG_LOGS": "1",
"SLEEP_SPEC_FAILURE": "0",
"STRIP_VENDOR": "1",
]
def ask_build_parameter = { ->
return input(message: "Build Parameters", id: "build_params",
parameters:[
[$class: 'ChoiceParameterDefinition',
choices: "0\n1", description: 'Leave container after build for debugging', name: 'LEAVE_CONTAINER'],
[$class: 'ChoiceParameterDefinition',
choices: "0\n1", description: 'Print all logs even on success', name: 'ALWAYS_PRINT_LOGS'],
[$class: 'ChoiceParameterDefinition',
choices: "0\n1", description: 'Print redis monitor logs', name: 'REDIS_MONITOR_LOGS'],
[$class: 'ChoiceParameterDefinition',
choices: "1\n0", description: 'Print detailed watchdog logs', name: 'WATCHDOG_LOGS'],
[$class: 'ChoiceParameterDefinition',
choices: "0\n1", description: 'Sleep on spec failure for debugging', name: 'SLEEP_SPEC_FAILURE'],
[$class: 'ChoiceParameterDefinition',
choices: "1\n0", description: 'Switch to make vendor/bundle/* compact', name: 'STRIP_VENDOR'],
[$class: 'ChoiceParameterDefinition',
choices: "false\ntrue", description: 'Rebuild cache image', name: 'REBUILD'],
[$class: 'ChoiceParameterDefinition',
choices: "1\n0", description: 'Print all ', name: 'SLEEP_SPEC_FAILURE'],
])
}
def write_build_env(label) {
def build_env="""# These parameters are read from bash and docker --env-file.
# So do not use single or double quote for the value part.
LEAVE_CONTAINER=${buildParams.LEAVE_CONTAINER}
ALWAYS_PRINT_LOGS=${buildParams.ALWAYS_PRINT_LOGS}
REDIS_MONITOR_LOGS=${buildParams.REDIS_MONITOR_LOGS}
SLEEP_SPEC_FAILURE=${buildParams.SLEEP_SPEC_FAILURE}
STRIP_VENDOR=${buildParams.STRIP_VENDOR}
REBUILD=${buildParams.REBUILD}
REPO_BASE_DIR=${env.REPO_BASE_DIR ?: ''}
BUILD_CACHE_DIR=${env.BUILD_CACHE_DIR ?: ''}
BUILD_OS=$label
RELEASE_SUFFIX=$RELEASE_SUFFIX
BRANCH=${env.BRANCH_NAME}
"""
writeFile(file: "build.env", text: build_env)
}
def checkout_and_merge() {
checkout scm
sh "git -c \"user.name=Axsh Bot\" -c \"[email protected]\" merge origin/develop"
}
@Field RELEASE_SUFFIX=null
def stage_rpmbuild(label) {
node("ci-build") {
stage("Build ${label}") {
checkout_and_merge()
write_build_env(label)
sh "./ci/ci.${label}/rspec_rpmbuild/build.sh ./build.env"
}
}
}
def stage_integration_test(label) {
node("multibox") {
stage("Integration test ${label}") {
checkout_and_merge()
write_build_env(label)
sh "./ci/ci.${label}/integration_test/build_and_run_in_docker.sh ./build.env"
}
}
}
node() {
stage("Checkout") {
try {
timeout(time: 10, unit :"SECONDS") {
buildParams = ask_build_parameter()
}
}catch(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException err) {
// Only ignore errors for timeout.
}
checkout scm
// http://stackoverflow.com/questions/36507410/is-it-possible-to-capture-the-stdout-from-the-sh-dsl-command-in-the-pipeline
// https://issues.jenkins-ci.org/browse/JENKINS-26133
RELEASE_SUFFIX=sh(returnStdout: true, script: "./ci/gen-dev-build-tag.sh").trim()
}
}
def jobName = "${env.JOB_NAME}".tokenize("/")[0]
stage_rpmbuild("${jobName}")
stage_integration_test("${jobName}")