forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-for-build.jenkinsfile
140 lines (136 loc) · 5.54 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
/*
* 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: '[email protected]', 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-C54xlarge-Docker-Host'
}
triggers {
parameterizedCron '''
H 1 * * * %INPUT_MANIFEST=2.16.1/opensearch-2.16.1.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux macos windows;BUILD_DISTRIBUTION=tar rpm deb zip
H 1 * * * %INPUT_MANIFEST=2.17.0/opensearch-2.17.0.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux macos windows;BUILD_DISTRIBUTION=tar rpm deb zip
H 1 * * * %INPUT_MANIFEST=2.17.0/opensearch-dashboards-2.17.0.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards;BUILD_PLATFORM=linux windows;BUILD_DISTRIBUTION=tar rpm deb zip
H 1 * * * %INPUT_MANIFEST=3.0.0/opensearch-3.0.0.yml;TARGET_JOB_NAME=distribution-build-opensearch;BUILD_PLATFORM=linux macos windows;BUILD_DISTRIBUTION=tar rpm deb zip
H 1 * * * %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
)
}
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}")
], wait: true
echo "Build succeeded, uploading build SHA for that job"
buildUploadManifestSHA(
inputManifest: "manifests/${INPUT_MANIFEST}",
jobName: "${TARGET_JOB_NAME}"
)
}
}
}
}
post {
always {
postCleanup()
}
}
}
}
post {
failure {
node(AGENT_X64) {
script {
publishNotification(
icon: ':warning:',
message: 'Failed checking for build to trigger',
credentialsId: 'jenkins-build-notice-webhook',
manifest: "${INPUT_MANIFEST}",
target_job_name: "${TARGET_JOB_NAME}"
)
postCleanup()
}
}
}
}
}