-
Notifications
You must be signed in to change notification settings - Fork 275
/
check-for-build.jenkinsfile
146 lines (143 loc) · 6.43 KB
/
check-for-build.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
lib = library(identifier: 'jenkins@1.0.4', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))
pipeline {
options {
timeout(time: 5, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '7'))
}
agent none
environment {
AGENT_X64 = 'Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host'
}
triggers {
parameterizedCron '''
H 1 * * * %INPUT_MANIFEST=2.19.0/opensearch-dashboards-2.19.0.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip;TEST_MANIFEST=2.19.0/opensearch-dashboards-2.19.0-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar
H 1 * * * %INPUT_MANIFEST=2.18.1/opensearch-2.18.1.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip;TEST_MANIFEST=2.18.1/opensearch-2.18.1-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar
H */6 * * * %INPUT_MANIFEST=1.3.20/opensearch-dashboards-1.3.20.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip;TEST_MANIFEST=1.3.20/opensearch-dashboards-1.3.20-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar
H 1 * * * %INPUT_MANIFEST=2.19.0/opensearch-2.19.0.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip;TEST_MANIFEST=2.19.0/opensearch-2.19.0-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar
H */6 * * * %INPUT_MANIFEST=1.3.20/opensearch-1.3.20.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip;TEST_MANIFEST=1.3.20/opensearch-1.3.20-test.yml;TEST_PLATFORM=linux;TEST_DISTRIBUTION=tar
H 4 * * * %INPUT_MANIFEST=3.0.0/opensearch-3.0.0.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip
H 4 * * * %INPUT_MANIFEST=3.0.0/opensearch-dashboards-3.0.0.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip
'''
}
parameters {
string(
name: 'INPUT_MANIFEST',
description: 'Input manifest under the manifests folder, e.g. 2.0.0/opensearch-2.0.0.yml.',
trim: true
)
string(
name: 'TEST_MANIFEST',
description: 'Test manifest under the manifests folder, e.g. 2.0.0/opensearch-2.0.0-test.yml. Currently only applicable for distribution-build-opensearch job',
trim: true
)
string(
name: 'TARGET_JOB_NAME',
description: 'Job to trigger if build has changed',
trim: true
)
string(
name: 'BUILD_PLATFORM',
description: 'Platform to build',
trim: true
)
string(
name: 'BUILD_DISTRIBUTION',
description: 'Distribution to build',
trim: true
)
string(
name: 'TEST_PLATFORM',
description: 'Platform to test',
trim: true
)
string(
name: 'TEST_DISTRIBUTION',
description: 'Distribution to test',
trim: true
)
}
stages {
stage('detect docker image + args') {
agent {
docker {
label AGENT_X64
image 'docker/library/alpine:3'
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
steps {
script {
dockerAgent = detectDockerAgent()
}
}
}
stage('trigger-build-if-needed') {
agent {
docker {
label AGENT_X64
image dockerAgent.image
args dockerAgent.args
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
steps {
script {
lock(resource: "CheckForBuild-${INPUT_MANIFEST}-${TARGET_JOB_NAME}", skipIfLocked: true) {
def sha = getManifestSHA(
inputManifest: "manifests/${INPUT_MANIFEST}",
jobName: "${TARGET_JOB_NAME}"
)
if (sha.exists) {
echo "Skipping, ${sha.path} already exists."
} else {
if (TARGET_JOB_NAME != 'distribution-build-opensearch' &&
TARGET_JOB_NAME != 'distribution-build-opensearch-dashboards') {
error "Job ${TARGET_JOB_NAME} is invalid"
}
build job: "${TARGET_JOB_NAME}", parameters: [
string(name: 'INPUT_MANIFEST', value: "${INPUT_MANIFEST}"),
string(name: 'TEST_MANIFEST', value: "${TEST_MANIFEST}"),
string(name: 'BUILD_PLATFORM', value: "${BUILD_PLATFORM}"),
string(name: 'BUILD_DISTRIBUTION', value: "${BUILD_DISTRIBUTION}"),
string(name: 'TEST_PLATFORM', value: "${TEST_PLATFORM}"),
string(name: 'TEST_DISTRIBUTION', value: "${TEST_DISTRIBUTION}")
], wait: true
echo "Build succeeded, uploading build SHA for that job"
buildUploadManifestSHA(
inputManifest: "manifests/${INPUT_MANIFEST}",
jobName: "${TARGET_JOB_NAME}"
)
}
}
}
}
post {
always {
postCleanup()
}
}
}
}
post {
always {
node(AGENT_X64) {
script {
postCleanup()
}
}
}
}
}