Skip to content

feat: Support build parameters in resource names, labels, and numbers#972

Merged
mPokornyETM merged 5 commits intomasterfrom
feature/build-param-resources
Apr 3, 2026
Merged

feat: Support build parameters in resource names, labels, and numbers#972
mPokornyETM merged 5 commits intomasterfrom
feature/build-param-resources

Conversation

@mPokornyETM
Copy link
Copy Markdown
Contributor

Linked issues

Fixes #159 — Allow to specify resource and label by build parameter
Fixes #202 — Allow build parameters as resource/label/number
Replaces #214 — Clean re-implementation on current master

Description

Allows \\ references in the Required Lockable Resources job property so that resource names, labels, and resource numbers can be resolved from build parameters at queue time and build start.

Changes

File What changed
\Utils.java\ Added \
equiredResources(Job, EnvVars)\ overload, \getParametersAsEnvVars(Queue.Item), \containsVariable(String)\
\LockableResourcesStruct.java\ Expand \
equiredNumber\ via \env.expand()\
\LockableResourcesQueueTaskDispatcher.java\ Pass build parameters from queue item to resource struct
\LockRunListener.java\ Pass \AbstractBuild\ environment to resource struct at build start
\RequiredResourcesProperty.java\ Form validation recognises \\ and shows warning instead of error
\Messages.properties\ Warning messages for parameter references
\FreeStyleProjectTest.java\ 3 new integration tests: parameterized resource name, label, number
\UtilsTest.java\ Unit test for \containsVariable()\

How it works

  1. Queue time — \LockableResourcesQueueTaskDispatcher.canRun()\ extracts build parameters from the queue item via \Utils.getParametersAsEnvVars(item)\ and passes them to \Utils.requiredResources(project, paramEnv)\
  2. Build start — \LockRunListener.onStarted()\ gets the build environment (which includes parameters) and passes it to the same overloaded method
  3. Struct expansion — \LockableResourcesStruct\ already calls \env.expand()\ on resource names and labels; now also expands
    equiredNumber\
  4. Form validation — \RequiredResourcesProperty.DescriptorImpl\ detects \\ patterns and returns a warning instead of failing validation

Differences from PR #214

  • Uses \edu.umd.cs.findbugs.annotations.NonNull\ (not \javax.annotation.Nonnull)
  • No unsafe casting — keeps @AncestorInPath Item\ signature for Pipeline compatibility
  • Proper \instanceof AbstractBuild\ guard in \LockRunListener\
  • Cleaner extraction via \Utils.getParametersAsEnvVars()\ utility
  • Full test coverage for all three parameterised paths

Testing

  • \mvn clean compile\ — passes
  • \UtilsTest.containsVariable\ — passes
  • \FreeStyleProjectTest.parameterizedResourceName\ — passes
  • \FreeStyleProjectTest.parameterizedLabel\ — passes
  • \FreeStyleProjectTest.parameterizedResourceNumber\ — passes
  • All existing tests pass (one pre-existing flaky timeout: \LockStepReserveInsideLockHonouredTest)

Checklist

  • Code compiles without errors
  • Tests pass
  • No new dependencies added
  • Commit message follows conventional format

@mPokornyETM mPokornyETM requested a review from a team as a code owner March 30, 2026 06:39
@github-actions github-actions Bot added java Pull requests that update Java code localization tests labels Mar 30, 2026
@mPokornyETM
Copy link
Copy Markdown
Contributor Author

Verified manually and it works:
image

image

@mPokornyETM mPokornyETM enabled auto-merge (squash) March 31, 2026 06:38
@mPokornyETM mPokornyETM added megre in 24 hours without review When nobody request a change or leave comment here I will merge it in 24 hours merge-in-2-days-without-review Auto-approve countdown and removed megre in 24 hours without review When nobody request a change or leave comment here I will merge it in 24 hours labels Mar 31, 2026
@github-actions github-actions Bot added merge-in-1-day-without-review Auto-approve countdown and removed merge-in-2-days-without-review Auto-approve countdown labels Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

⚠️ Auto-merge countdown: This PR will be auto-approved in 1 day(s) if no review is submitted.

@github-actions github-actions Bot force-pushed the feature/build-param-resources branch from 997e67f to 7ddfe2a Compare April 1, 2026 19:37
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

⏸️ Auto-merge countdown PAUSED: CI checks are not passing. The countdown will resume when all checks are green.

Allow  references in the Required Lockable Resources job property
so that resource names, labels, and resource numbers can be resolved from
build parameters at queue time and build start.

Changes:
- Utils: add requiredResources(Job, EnvVars) overload and
  getParametersAsEnvVars(Queue.Item) to extract build parameters
- LockableResourcesStruct: expand requiredNumber via env.expand()
- LockableResourcesQueueTaskDispatcher: pass build parameters from
  queue item to resource struct for early expansion
- LockRunListener: pass AbstractBuild environment to resource struct
  so parameter references are expanded at build start
- RequiredResourcesProperty: form validation now recognises \
  patterns and shows a warning instead of an error
- Messages.properties: add warning messages for parameter references
- Tests: add parameterizedResourceName, parameterizedLabel,
  parameterizedResourceNumber tests and UtilsTest.containsVariable

Fixes #159, Fixes #202
Replaces #214
- Utils.getParametersAsEnvVars: remove unnecessary try-catch (APIs do not
  throw checked exceptions)
- LockRunListener.onStarted: catch IOException | InterruptedException
  instead of generic Exception
Add 7 new test methods covering all code paths:
- No actions (empty list)
- Single parameter
- Multiple parameters in one action
- Multiple ParametersAction instances
- Null parameter value (skipped)
- Non-string value (converted via toString)
- Duplicate key across actions (later wins)

Also fix @NoExternalUse annotations to use @restricted(NoExternalUse.class)
and add missing imports for ExcludeFromJacocoGeneratedReport.
@github-actions github-actions Bot force-pushed the feature/build-param-resources branch from 7ddfe2a to c995a5c Compare April 2, 2026 11:32
@github-actions github-actions Bot removed the merge-in-1-day-without-review Auto-approve countdown label Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Auto-approved: No review received within 3 days. Merging now.

@github-actions github-actions Bot added the merged-without-review Auto-approve countdown label Apr 3, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Auto-approved: no review received within 3 days of opening.

@mPokornyETM mPokornyETM merged commit 59635fe into master Apr 3, 2026
20 of 21 checks passed
@mPokornyETM mPokornyETM deleted the feature/build-param-resources branch April 3, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement java Pull requests that update Java code localization merged-without-review Auto-approve countdown tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use build parameter as the number of resources to lock freestyle project: use build parameter as resource

1 participant