Skip to content

Commit 75cd83d

Browse files
committed
Chown workspace for non-root containers
When running jobs on Kubernetes containers instead of the Jenkins built-in node, containers running as a non-root user have problems cleaning the workspace. Run chown on jnlp so the workspace matches runAsUser/runAsGroup before forceCleanupWS. Signed-off-by: Noam Tsemah <ntsemah@nvidia.com>
1 parent 839904f commit 75cd83d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/com/mellanox/cicd/Matrix.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ def forceCleanupWS() {
159159
}
160160
}
161161

162+
def chownWorkspace(runAsUser, runAsGroup) {
163+
if ("${runAsUser}" != "0" && "${runAsGroup}" != "0") {
164+
sh """
165+
if [ -n "\${WORKSPACE}" ]; then
166+
chown -R ${runAsUser}:${runAsGroup} "\${WORKSPACE}" 2>/dev/null || true
167+
fi
168+
if [ -e "\${WORKSPACE}@tmp" ]; then
169+
chown -R ${runAsUser}:${runAsGroup} "\${WORKSPACE}@tmp" 2>/dev/null || true
170+
fi
171+
"""
172+
}
173+
}
162174

163175
def getArchConf(config, arch) {
164176

@@ -939,6 +951,7 @@ spec:
939951
{
940952
retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
941953
node(POD_LABEL) {
954+
chownWorkspace(runAsUser, runAsGroup)
942955
stage (branchName) {
943956
container(cname) {
944957
runSteps(image, config, branchName, axis, steps, 'k8')

0 commit comments

Comments
 (0)