diff options
| author | Ryan Schanzenbacher <ryan@rschanz.org> | 2026-06-10 18:07:04 -0400 |
|---|---|---|
| committer | Ryan Schanzenbacher <ryan@rschanz.org> | 2026-06-10 18:07:04 -0400 |
| commit | 6709dfe2047bf7fa6e298e96add28814cafd92b7 (patch) | |
| tree | fccfafc21e42a1a5506b875507e55e3647ebcb8b | |
| parent | 43db0461b5114d77d7fdd7ed4a76a76275ad8385 (diff) | |
test 2
| -rw-r--r-- | Jenkinsfile | 39 | ||||
| -rw-r--r-- | 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 { | |||
| 10 | steps { | 10 | steps { |
| 11 | script { | 11 | script { |
| 12 | def base = env.CHANGE_TARGET ? "origin/${env.CHANGE_TARGET}" : "HEAD~1" | 12 | def base = env.CHANGE_TARGET ? "origin/${env.CHANGE_TARGET}" : "HEAD~1" |
| 13 | def changed = sh( | 13 | |
| 14 | script: "git diff --name-only ${base} HEAD | cut -d/ -f1 | sort -u", | 14 | // returnStdout gives a String. Trim, split, and FORCE to a List. |
| 15 | def diffOutput = sh( | ||
| 16 | script: "git diff --name-only ${base} HEAD || true", | ||
| 15 | returnStdout: true | 17 | returnStdout: true |
| 16 | ).trim().split('\n') | 18 | ).trim() |
| 19 | |||
| 20 | // 'as List' avoids the non-serializable String[] array | ||
| 21 | def changedFiles = diffOutput ? (diffOutput.split('\n') as List) : [] | ||
| 22 | |||
| 23 | // Build a plain List of unique top-level dirs (Strings only) | ||
| 24 | def candidates = [] | ||
| 25 | for (String f : changedFiles) { | ||
| 26 | def top = f.split('/')[0] | ||
| 27 | if (top && !candidates.contains(top)) { | ||
| 28 | candidates.add(top) | ||
| 29 | } | ||
| 30 | } | ||
| 17 | 31 | ||
| 18 | // keep only dirs containing a Dockerfile | 32 | // fileExists is a pipeline STEP, so it must stay in CPS land |
| 19 | env.IMAGES_TO_BUILD = changed.findAll { | 33 | // (i.e. a normal for-loop, NOT inside @NonCPS or a findAll closure) |
| 20 | fileExists("${it}/Dockerfile") | 34 | def toBuild = [] |
| 21 | }.join(',') | 35 | for (String dir : candidates) { |
| 36 | if (fileExists("${dir}/Dockerfile")) { | ||
| 37 | toBuild.add(dir) | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | // Store only a plain String in env | ||
| 42 | env.IMAGES_TO_BUILD = toBuild.join(',') | ||
| 43 | echo "Images to build: ${env.IMAGES_TO_BUILD ?: '(none)'}" | ||
| 22 | } | 44 | } |
| 23 | } | 45 | } |
| 24 | } | 46 | } |
| 25 | |||
| 26 | stage('Build & push') { | 47 | stage('Build & push') { |
| 27 | when { expression { env.IMAGES_TO_BUILD } } | 48 | when { expression { env.IMAGES_TO_BUILD } } |
| 28 | steps { | 49 | steps { |
| @@ -49,4 +70,4 @@ pipeline { | |||
| 49 | } | 70 | } |
| 50 | } | 71 | } |
| 51 | } | 72 | } |
| 52 | } \ No newline at end of file | 73 | } |
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 | |||
| 2 | 2 | ||
| 3 | RUN apt update && apt install -y git | 3 | RUN apt update && apt install -y git |
| 4 | 4 | ||
| 5 | RUN git --version | ||
| 6 | |||
| 5 | ENTRYPOINT ['git'] | 7 | ENTRYPOINT ['git'] |
