From 6709dfe2047bf7fa6e298e96add28814cafd92b7 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Wed, 10 Jun 2026 18:07:04 -0400 Subject: test 2 --- Jenkinsfile | 39 ++++++++++++++++++++++++++++++--------- test-1/Dockerfile | 2 ++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f7f3f28..3b197f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,19 +10,40 @@ pipeline { steps { script { def base = env.CHANGE_TARGET ? "origin/${env.CHANGE_TARGET}" : "HEAD~1" - def changed = sh( - script: "git diff --name-only ${base} HEAD | cut -d/ -f1 | sort -u", + + // returnStdout gives a String. Trim, split, and FORCE to a List. + def diffOutput = sh( + script: "git diff --name-only ${base} HEAD || true", returnStdout: true - ).trim().split('\n') + ).trim() + + // 'as List' avoids the non-serializable String[] array + def changedFiles = diffOutput ? (diffOutput.split('\n') as List) : [] + + // Build a plain List of unique top-level dirs (Strings only) + def candidates = [] + for (String f : changedFiles) { + def top = f.split('/')[0] + if (top && !candidates.contains(top)) { + candidates.add(top) + } + } - // keep only dirs containing a Dockerfile - env.IMAGES_TO_BUILD = changed.findAll { - fileExists("${it}/Dockerfile") - }.join(',') + // fileExists is a pipeline STEP, so it must stay in CPS land + // (i.e. a normal for-loop, NOT inside @NonCPS or a findAll closure) + def toBuild = [] + for (String dir : candidates) { + if (fileExists("${dir}/Dockerfile")) { + toBuild.add(dir) + } + } + + // Store only a plain String in env + env.IMAGES_TO_BUILD = toBuild.join(',') + echo "Images to build: ${env.IMAGES_TO_BUILD ?: '(none)'}" } } } - stage('Build & push') { when { expression { env.IMAGES_TO_BUILD } } steps { @@ -49,4 +70,4 @@ pipeline { } } } -} \ No newline at end of file +} diff --git a/test-1/Dockerfile b/test-1/Dockerfile index b4e1dd4..f32e3e8 100644 --- a/test-1/Dockerfile +++ b/test-1/Dockerfile @@ -2,4 +2,6 @@ FROM ubuntu:latest RUN apt update && apt install -y git +RUN git --version + ENTRYPOINT ['git'] -- cgit v1.3