Skip to content

[CK] Extract Jenkinsfile helpers into vars/ck.groovy shared library#7743

Merged
amd-justchen merged 18 commits into
developfrom
users/brockhargreaves-amd/ck/jenkinsfile-redesign
Jun 1, 2026
Merged

[CK] Extract Jenkinsfile helpers into vars/ck.groovy shared library#7743
amd-justchen merged 18 commits into
developfrom
users/brockhargreaves-amd/ck/jenkinsfile-redesign

Conversation

@brockhargreaves-amd

Copy link
Copy Markdown
Contributor

Motivation

The CK Jenkinsfile is a 2,215-line monolith mixing helper function definitions with pipeline stage declarations. This makes it difficult to review, modify, or extend CI stages without wading through unrelated infrastructure code.

Technical Details

Extract all helper functions from the Jenkinsfile into vars/ck.groovy, loaded at runtime via ck = load "vars/ck.groovy" in the first stage. The Jenkinsfile is reduced from 2,215 lines to 810 lines containing only the pipeline structure.

  • 36 helper functions moved to ck.groovy with no logic changes
  • 10 new stage-wrapper functions (runBuildCKAndTests, runTileEngineGemmTests, runClangFormat, etc.) extract inline environment{}/steps{} business logic from stages, eliminating the MethodTooLargeException caused by CPS-transformed shell strings exceeding the JVM 64KB bytecode limit
  • All ck. method calls in steps{} blocks wrapped in script{} as required by Jenkins Declarative Pipeline
  • rocmnode() remains in the Jenkinsfile (needed for agent{} labels before ck is loaded)
  • CRON_SETTINGS / POLL_SPEC remain in the Jenkinsfile (triggers{} evaluates at parse time before any workspace is available)
  • No stage names changed

Test Plan

  • Jenkinsfile validated against the Jenkins Pipeline Linter (/pipeline-model-converter/validate)
  • All 35 shared helper functions diffed line-by-line against develop to verify no regressions
  • Merge from develop incorporated and verified (gfx1250 stage, ROCm 7.13 default, cmake_build updates)

Test Result

  • Linter: passes
  • Function diff vs develop: all 35 functions match exactly
  • Awaiting Jenkins run to confirm end-to-end stage execution

Submission Checklist

brockhargreaves-amd and others added 6 commits May 13, 2026 20:02
Move all 35 helper functions from the monolithic Jenkinsfile into
a separate vars/ck.groovy file, following MiOpen's existing pattern.
Pure code movement — no logic changes, no renames, no stage name
changes.

rocmnode() remains in the Jenkinsfile because it's used in agent{}
labels throughout the declarative pipeline. The library is loaded
in the "Determine CI Execution" stage via checkout scm + load.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Jenkins Declarative Pipeline does not allow method calls on objects
(ck.foo()) directly in steps{} blocks — they must be inside script{}
blocks. The original bare function calls worked because they were in
the same compilation unit, but loading via ck = load "vars/ck.groovy"
makes them object method calls.

Also fixes ck.ck.checkoutComposableKernel() typo (double ck prefix).

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Extract all inline shell commands and build arguments from Jenkinsfile
environment{} blocks into named functions in ck.groovy. Jenkinsfile now
contains only pipeline structure: stage names, when conditions, agent
labels, and single-line ck.runXxx() calls.

New functions: runClangFormat, runClangFormatAndCppcheck,
runFullGroupedConvTileTests, runGroupedConvLargeCaseTests,
runComprehensiveConvDatasetTests, runTileEngineBasicTests,
runTileEngineGemmTests, runBuildCKAndTests, runBuildInstancesOnly.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Resolved conflicts by keeping our clean ck.groovy-based structure throughout.
Incorporated develop's new additions:
- Add BUILD_GFX1250 param and gfx1250 build stage (private docker, no reboot)
- Add runBuildCKForGfx1250() to ck.groovy
- Update cmake_build() to use default ROCm compiler for gfx1250 targets
- ROCMVERSION default already updated to 7.13 in our branch
- TILE_ENGINE_SAMPLING_TIER=daily already in our runTileEngineGemmTests()

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Phase 1 copied helper functions from the original monolith, but develop
had already updated three of them before our branch point:

- cmake_build: restore RUN_ROCM_CK_TESTS cmake flag, ninja trace archival
  after full builds, gfx1250 skip-tests logic, and BUILD_INSTANCES_ONLY
  package stashing that were added in commits 316fded and de93737
- getBaseDockerImageName: revert private-registry branching by ROCM version
  (develop reverted this back to always use public registry)
- getPytorchTestsCmds: restore mkdir/cp from Jenkins workspace path
  (develop updated this from /tmp/pytorch in commit 7e032ad)

Also restore show_node_info() hostname line from commit 47e8768
(John Robbins) that was dropped during Phase 1 extraction.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
gfx1250 is now a case in the existing switch rather than a separate
function. Its unique args (private docker image, no_reboot,
DISABLE_DL_KERNELS) are passed via extraBuildArgs/extraSetupArgs.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Develop added deleteDir() at the top of 25 stage steps{} blocks to
ensure a clean workspace before each stage runs. These were lost when
conflicts were resolved by keeping our side. Restores them in the same
stages that develop had them, excluding the 5 downstream test stages
(Pytorch, AITER, FA) which never had them.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Composable Kernel Jenkins pipeline by moving the Jenkinsfile’s helper logic into a separately loaded Groovy script (vars/ck.groovy), leaving the Jenkinsfile primarily responsible for declarative pipeline structure and stage definitions.

Changes:

  • Added projects/composablekernel/vars/ck.groovy containing the extracted helper functions plus new stage-wrapper functions.
  • Simplified projects/composablekernel/Jenkinsfile to load the helper script once and call ck.* helpers (wrapped in script {} where required).
  • Replaced several large inline stage environment{}/steps{} command blocks with wrapper calls (e.g., clang-format/cppcheck, grouped-conv tests, tile-engine tests, build-and-test stages).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
projects/composablekernel/vars/ck.groovy New loaded helper script containing extracted pipeline helpers and stage-wrapper functions.
projects/composablekernel/Jenkinsfile Updated declarative pipeline to load ck.groovy and delegate stage logic to ck.* helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread projects/composablekernel/Jenkinsfile
Comment thread projects/composablekernel/vars/ck.groovy
Comment thread projects/composablekernel/vars/ck.groovy
…ineGemmTests

Restore TILE_ENGINE_SAMPLING_TIER=daily cmake flag for all three arch
branches (gfx942, gfx950, gfx1201) and correct gfx942's benchmark
output filename from results.json to gemm_universal_results.json,
matching develop.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Comment thread projects/composablekernel/Jenkinsfile
Comment thread projects/composablekernel/vars/ck.groovy Outdated
Comment thread projects/composablekernel/vars/ck.groovy Outdated
brockhargreaves-amd and others added 2 commits May 27, 2026 12:02
- Drop class Version and parseVersion() from ck.groovy; both became dead
  code when getBaseDockerImageName was synced to develop (which removed
  the ROCm version branch that was their only call site)
- Change `def ck` to `ck = null` at script scope to match MiOpen's
  utils pattern (global binding vs local variable)
- Add null guard around `ck = load` to match MiOpen's lazy-load idiom

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
@tenpercent

Copy link
Copy Markdown
Contributor

curious if you plan to add tests for the pipeline code? e.g. https://github.com/jenkinsci/JenkinsPipelineUnit

brockhargreaves-amd and others added 2 commits May 28, 2026 14:55
Three functional changes from develop commit e34ac06:

1. cmake_build: add BUILD_INSTANCES_ONLY to profiler package build condition
2. process_results: move sh steps inside each try{} block so a missing
   stash does not abort subsequent uploads
3. runBuildInstancesOnly: add GPU_ARCHS and setup_args=NO_CK_BUILD

Jenkinsfile conflict resolved by keeping ck.runBuildInstancesOnly() and
discarding the monolith helpers from develop (already in ck.groovy).

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Jenkins charset reader rejected the UTF-8 right-arrow (→) on line 24.
Replace with ASCII -> to avoid MalformedInputException.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>

@amd-anclark amd-anclark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Had a few nit-picks and a question around moving your ck scripts into an actual @Library.

Comment thread projects/composablekernel/vars/ck.groovy
Comment thread projects/composablekernel/Jenkinsfile Outdated
}
}
}
stage("Process Performance Test Results")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't part of this PR, but just calling out the Process Performance Test Results does not have the SHOULD_RUN_CI guard in place. We may want to add this later.

Comment thread projects/composablekernel/Jenkinsfile Outdated
script {
checkoutComposableKernel()
env.SHOULD_RUN_CI = String.valueOf(params.FORCE_CI.toBoolean() || shouldRunCICheck())
checkout scm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my other comment; if we move your scripts into a shared library, we won't have to call "checkout scm" and "ck.checkoutComposableKernel()" in the same stage.

Comment thread projects/composablekernel/vars/ck.groovy
Comment thread projects/composablekernel/vars/ck.groovy Outdated
Comment thread projects/composablekernel/vars/ck.groovy
- Replace inline load mechanism with @Library('ck') annotation for
  restart-from-stage safety (ck is available at parse time)
- Move smart build comment block from ck.groovy to Jenkinsfile
- Fix indentation in Build_CK performance test block
- Remove return this from ck.groovy (not needed for shared libraries)

Requires one-time Jenkins admin setup: register Global Pipeline Library
named 'ck' pointing to this repo with Library Path
'projects/composablekernel/'.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
brockhargreaves-amd and others added 4 commits May 29, 2026 13:19
@Library requires Jenkins admin config and always loads from a fixed
branch, preventing testing of ck.groovy changes on PR branches.

Instead, use a loadCk() guard function that each stage calls before
using ck.*. The null check makes it a no-op after first load, and
restart-from-stage works because every stage can bootstrap itself.

Also fixes indentation in FMHA and process_results script blocks.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
- Resolve merge conflict: keep refactored Jenkinsfile, discard
  monolith helpers from develop
- Apply PR #7894 fix to ck.groovy: wrap docker manifest inspect
  with withDockerRegistry credentials
- Remove redundant nested script {} block in pipeline failure post

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@brockhargreaves-amd brockhargreaves-amd requested a review from a team as a code owner May 31, 2026 00:04
@amd-justchen

Copy link
Copy Markdown
Contributor

Hi guys, we have another pr that just refactors the Jenkinsfile:
#7743
but since it moves some scripts into a new subfolder it can't bypass therock ci and a bunch of tests are just timing out:
https://github.com/ROCm/rocm-libraries/actions/runs/26756658967/job/78902803059?pr=7743

As gardener, I see that this is only modifying the Jenkinsfile, so will allow this to bypass TheRock CI as it's unrelated.

@amd-justchen amd-justchen merged commit 15ef85c into develop Jun 1, 2026
126 of 156 checks passed
@amd-justchen amd-justchen deleted the users/brockhargreaves-amd/ck/jenkinsfile-redesign branch June 1, 2026 21:09
assistant-librarian Bot pushed a commit to ROCm/composable_kernel that referenced this pull request Jun 1, 2026
[CK] Extract Jenkinsfile helpers into vars/ck.groovy shared
 library (#7743)

## Motivation
The CK Jenkinsfile is a 2,215-line monolith mixing helper function
definitions with pipeline stage declarations. This makes it difficult to
review, modify, or extend CI stages without wading through unrelated
infrastructure code.

## Technical Details
Extract all helper functions from the Jenkinsfile into vars/ck.groovy,
loaded at runtime via ck = load "vars/ck.groovy" in the first stage. The
Jenkinsfile is reduced from 2,215 lines to 810 lines containing only the
pipeline structure.

- 36 helper functions moved to ck.groovy with no logic changes
- 10 new stage-wrapper functions (runBuildCKAndTests,
runTileEngineGemmTests, runClangFormat, etc.) extract inline
environment{}/steps{} business logic from stages, eliminating the
MethodTooLargeException caused by CPS-transformed shell strings
exceeding the JVM 64KB bytecode limit
- All ck. method calls in steps{} blocks wrapped in script{} as required
by Jenkins Declarative Pipeline
- rocmnode() remains in the Jenkinsfile (needed for agent{} labels
before ck is loaded)
- CRON_SETTINGS / POLL_SPEC remain in the Jenkinsfile (triggers{}
evaluates at parse time before any workspace is available)
- No stage names changed

## Test Plan
- Jenkinsfile validated against the Jenkins Pipeline Linter
(/pipeline-model-converter/validate)
- All 35 shared helper functions diffed line-by-line against develop to
verify no regressions
- Merge from develop incorporated and verified (gfx1250 stage, ROCm 7.13
default, cmake_build updates)

## Test Result
- Linter: passes
- Function diff vs develop: all 35 functions match exactly
- Awaiting Jenkins run to confirm end-to-end stage execution

## Submission Checklist

- [ x ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants