Skip to content

Commit 78b7b47

Browse files
v1vnarph
authored andcommitted
ci: support dynamic stages (docs only, packaging, k8s) (#36)
1 parent 487fea9 commit 78b7b47

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

.ci/Jenkinsfile

+38-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ pipeline {
4646
deleteDir()
4747
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
4848
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
49+
dir("${BASE_DIR}"){
50+
setEnvVar('ONLY_DOCS', isGitRegionMatch(patterns: [ '.*\\.(asciidoc|md)' ], shouldMatchAll: true).toString())
51+
setEnvVar('PACKAGING_CHANGES', isGitRegionMatch(patterns: [ '(^dev-tools/packaging/.*|.ci/Jenkinsfile)' ], shouldMatchAll: false).toString())
52+
setEnvVar('K8S_CHANGES', isGitRegionMatch(patterns: [ '(^deploy/kubernetes/.*|^version/docs/version.asciidoc)' ], shouldMatchAll: false).toString())
53+
}
4954
}
5055
}
5156
stage('Lint'){
@@ -66,6 +71,17 @@ pipeline {
6671
}
6772
}
6873
stage('Test') {
74+
when {
75+
// Always when running builds on branches/tags
76+
// On a PR basis, skip if changes are only related to docs.
77+
anyOf {
78+
not { changeRequest() } // If no PR
79+
allOf { // If PR and no docs changes
80+
expression { return env.ONLY_DOCS == "false" }
81+
changeRequest()
82+
}
83+
}
84+
}
6985
failFast false
7086
matrix {
7187
agent {label "${PLATFORM}"}
@@ -108,10 +124,15 @@ pipeline {
108124
}
109125
stage('K8s') {
110126
when {
111-
// TODO: Run only if changes in
112-
// - "^deploy/kubernetes/.*"
113-
// - "^version/docs/version.asciidoc"
114-
expression { return env.PLATFORM == 'ubuntu-20.04 && immutable' }
127+
// Always when running builds on branches/tags
128+
// Enable if k8s related changes.
129+
allOf {
130+
expression { return env.PLATFORM == 'ubuntu-20.04 && immutable' }
131+
anyOf {
132+
not { changeRequest() } // If no PR
133+
expression { return env.K8S_CHANGES == "true" }
134+
}
135+
}
115136
}
116137
steps {
117138
runK8s(k8sVersion: 'v1.23.0', kindVersion: 'v0.11.1', context: "K8s-${PLATFORM}")
@@ -124,7 +145,8 @@ pipeline {
124145
anyOf {
125146
expression { return env.GITHUB_COMMENT?.contains('package') }
126147
expression { matchesPrLabel(label: 'ci:package') }
127-
// not { changeRequest() }
148+
not { changeRequest() }
149+
expression { return env.PACKAGING_CHANGES == "true" }
128150
}
129151
// Run packaging only for the linux specific arch
130152
expression { return (PLATFORM.contains('ubuntu') || PLATFORM.contains('aarch64')) }
@@ -170,10 +192,17 @@ pipeline {
170192
}
171193
stage('K8s') {
172194
when {
173-
// TODO: Run only if changes in
174-
// - "^deploy/kubernetes/.*"
175-
// - "^version/docs/version.asciidoc"
176-
not { changeRequest() }
195+
// Always when running builds on branches/tags
196+
// On a PR basis, skip if changes are only related to docs.
197+
// Enable if k8s related changes.
198+
anyOf {
199+
not { changeRequest() } // If no PR
200+
allOf { // If PR and no docs changes
201+
expression { return env.ONLY_DOCS == "false" }
202+
changeRequest()
203+
}
204+
expression { return env.K8S_CHANGES == "true" } // If k8s changes
205+
}
177206
}
178207
steps {
179208
runAllK8s(["v1.23.0", "v1.22.0", "v1.21.1", "v1.20.7", "v1.19.11", "v1.18.19"])

0 commit comments

Comments
 (0)