Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 57e46fc

Browse files
committed
CI Jenkinsfile: change rotation and deletion of previous workspaces
Recantly added workspace rename did not happen if build failed, causing longer duration in next clean stage, but what's worse, failed workspace was not preserved, contrary to what we need. Moving rename operation to finally block would add race possibilities. So we change the workspaces naming scheme. Workspace gets name with CI_BUILD_ID from very start, thus eliminating need to rename and risk of race. Older workspaces get deleted as CI_BUILD_ID ensures ordered-in-time series. Use regex in deletion and separate pass for temp.dirs. Workspace name prefix is shortened to ci- for shorter path names. Signed-off-by: Olev Kartau <olev.kartau@intel.com>
1 parent c1cf872 commit 57e46fc

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Jenkinsfile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def global_sum_log = ""
2828
def added_commits = ""
2929
def builder_node = ""
3030
def builder_wspace = ""
31-
def slot_name = "builder-slot-"
31+
def slot_name = "ci-"
3232
// reasonable value: keep few recent, dont take risk to fill disk
3333
int num_build_dirs_to_keep = 4
3434

@@ -48,7 +48,7 @@ def script_env = """
4848
try {
4949
timestamps {
5050
node('rk-docker') {
51-
ws("workspace/${slot_name}${env.EXECUTOR_NUMBER}") {
51+
ws("workspace/${slot_name}${ci_build_id}") {
5252
// remember node and workspace needed by workspace cleaner
5353
builder_node = "${env.NODE_NAME}"
5454
builder_wspace = "${env.WORKSPACE}"
@@ -102,11 +102,6 @@ try {
102102
added_commits = readFile("added_commits")
103103
}
104104
} // ws
105-
// rotate workspace out of way, rename using CI_BUILD_ID.
106-
// Older trees are deleted later in test_runs[], without keeping build waiting.
107-
ws("workspace") {
108-
sh "mv ${builder_wspace} ${builder_wspace}.ci-prev.${ci_build_id}"
109-
}
110105
} // node
111106
} // timestamps
112107

@@ -301,12 +296,17 @@ def step_xunit() {
301296
}
302297

303298
// Delete older builder trees.
304-
// While majority/regular workspaces are named builder-slot-0, (for EXECUTOR=0),
305-
// Jenkins may create additional trees as builder-slot-0_X.
306-
// Wildcard covers all such workspaces, dont want some pattern filling disk independently.
299+
// While majority/regular workspaces are named ci-CI_BUILD_ID,
300+
// Jenkins may create additional trees as ci-build-CI_BUILD_ID_<NUM>
301+
// Regex with underscore should cover all such workspaces.
307302
def trim_build_dirs(slotname, num_to_keep) {
308303
sh """
309-
dirs=`find ${env.WORKSPACE} -mindepth 1 -maxdepth 1 -type d -name "${slotname}*.ci-prev.*" |sort -n |head -n -${num_to_keep} |tr '\n' ' '`
304+
# tmpdirs in separate pass
305+
dirs=`find . -mindepth 1 -maxdepth 1 -type d -regex ".*/${slotname}[0-9_-]*-build-[0-9_]*.*tmp\$" |sort -n |head -n -${num_to_keep} |tr '\n' ' '`
306+
if [ -n "\${dirs}" ]; then
307+
ionice -c 3 rm -fr \$dirs
308+
fi
309+
dirs=`find . -mindepth 1 -maxdepth 1 -type d -regex ".*/${slotname}[0-9_-]*-build-[0-9_]*\$" |sort -n |head -n -${num_to_keep} |tr '\n' ' '`
310310
if [ -n "\${dirs}" ]; then
311311
ionice -c 3 rm -fr \$dirs
312312
fi

0 commit comments

Comments
 (0)