forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-for-build.jenkinsfile
113 lines (110 loc) · 4.28 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
lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm))
pipeline {
options {
timeout(time: 5, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '7'))
}
agent none
environment {
AGENT_X64 = 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host'
}
triggers {
parameterizedCron '''
H/60 * * * * %INPUT_MANIFEST=2.3.0/opensearch-dashboards-2.3.0.yml;TEST_MANIFEST=2.3.0/opensearch-dashboards-2.3.0-test.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards
H/60 * * * * %INPUT_MANIFEST=2.3.0/opensearch-2.3.0.yml;TEST_MANIFEST=2.3.0/opensearch-2.3.0-test.yml;TARGET_JOB_NAME=distribution-build-opensearch
H 1 * * * %INPUT_MANIFEST=3.0.0/opensearch-3.0.0.yml;TARGET_JOB_NAME=distribution-build-opensearch
H 1 * * * %INPUT_MANIFEST=3.0.0/opensearch-dashboards-3.0.0.yml;TARGET_JOB_NAME=distribution-build-opensearch-dashboards
'''
}
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
)
}
stages {
stage('detect docker image + args') {
agent {
docker {
label AGENT_X64
image 'alpine:3'
alwaysPull true
}
}
steps {
script {
dockerAgent = detectDockerAgent()
}
}
}
stage('trigger-build-if-needed') {
agent {
docker {
label AGENT_X64
image dockerAgent.image
args dockerAgent.args
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}")
], 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()
}
}
}
}
}