Skip to content

Support custom labels on GCE agent VMs#551

Merged
gbhat618 merged 6 commits into
jenkinsci:developfrom
mikecirioli:support-custom-labels
Jun 9, 2026
Merged

Support custom labels on GCE agent VMs#551
gbhat618 merged 6 commits into
jenkinsci:developfrom
mikecirioli:support-custom-labels

Conversation

@mikecirioli

@mikecirioli mikecirioli commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Closes #170

What this does

Adds support for setting custom GCP labels (key-value pairs) on the GCE agent VMs the plugin provisions. This is the plugin equivalent of gcloud compute instances create --labels=[KEY=VALUE,...], and mirrors the existing custom metadata feature.

Labels differ from metadata: a label value is a single word with no spaces (max 63 chars), so the value field is a single-line text box rather than a textarea. Per the existing GCE convention, there is no doCheckXXX form validation - GCP rejects invalid labels at instance-creation time.

How it works

A new CustomLabelItem describable holds each key-value pair. InstanceConfiguration gains an optional customLabels list, exposed in the form UI and via Configuration as Code. The labels are folded into the instance's label map before the system labels are applied, so user labels never clobber the plugin's internal labels, and template-defined labels keep their existing precedence.

CasC example:

customLabels:
  - key: test-label-key
    value: test-label-value
  - key: team
    value: jenkins

UI

Screenshot_20260605_164528
$ kubectl exec -n cbci "$pod" -- grep -n -A6 customLabels /var/jenkins_home/core-casc-bundle/jcasc/jenkins.yaml
  116:        customLabels:
  117-          - key: test-label-key
  118-            value: test-label-value
  119-          - key: team
  120-            value: jenkins
  121-        minimumNumberOfInstances: 0
  122-        minimumNumberOfSpareInstances: 1

Testing

  • Unit tests for the label fold (custom labels applied, empty keys skipped, system label preserved, null-safe).
  • Config round-trip test asserting customLabels persists through the form.
  • CasC round-trip test.
  • An integration test (ComputeEngineCloudCustomLabelsIT) that provisions a real VM via CasC and asserts the labels land on the instance.

Verified end to end on a live cluster: the configured labels appear on the provisioned GCE VM alongside the plugin's system labels.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikecirioli

Copy link
Copy Markdown
Contributor Author

Need to create a tracking issue and then will take this out of draft

@gbhat618

gbhat618 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Need to create a tracking issue and then will take this out of draft

one exists - #170 😄

need to also update the user visible documentation for this feature usage

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring custom GCP instance labels (key/value pairs) on provisioned GCE agent VMs, exposed via both Jenkins UI and Configuration as Code, with test coverage across unit, CasC, and integration layers.

Changes:

  • Introduces CustomLabelItem and wires customLabels into InstanceConfiguration and the Jenkins configuration UI.
  • Merges configured custom labels into the instance label map during provisioning.
  • Adds/extends unit tests, CasC round-trip assertions, and an integration test to verify labels land on real instances.

Reviewed changes

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

Show a summary per file
File Description
src/main/java/com/google/jenkins/plugins/computeengine/InstanceConfiguration.java Adds customLabels and folds them into the effective label map during instance creation.
src/main/java/com/google/jenkins/plugins/computeengine/CustomLabelItem.java New describable for a single label key/value pair.
src/main/resources/com/google/jenkins/plugins/computeengine/InstanceConfiguration/config.jelly Exposes a repeatable “Custom labels” section in the instance configuration UI.
src/main/resources/com/google/jenkins/plugins/computeengine/CustomLabelItem/config.jelly UI fragment for editing a label key/value entry.
src/test/java/com/google/jenkins/plugins/computeengine/InstanceConfigurationTest.java Adds unit tests for label folding behavior (including skipping empty keys and preserving system label).
src/test/java/com/google/jenkins/plugins/computeengine/ConfigAsCodeTest.java Extends CasC assertions to cover customLabels.
src/test/java/com/google/jenkins/plugins/computeengine/integration/ComputeEngineCloudCustomLabelsIT.java New integration test that provisions a VM and asserts the instance labels.
src/test/resources/com/google/jenkins/plugins/computeengine/configuration-as-code.yml Adds example customLabels configuration for CasC tests.
src/test/resources/com/google/jenkins/plugins/computeengine/integration/custom-labels-casc.yml New CasC bundle used by the integration test.

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

@gbhat618 gbhat618 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.

lgtm; a couple of comments about tests.
also need readme updates to mention the new user visible feature

@gbhat618 gbhat618 added the enhancement New feature or request label Jun 8, 2026
@mikecirioli mikecirioli marked this pull request as ready for review June 8, 2026 12:20
@mikecirioli mikecirioli requested a review from a team as a code owner June 8, 2026 12:20
mikecirioli and others added 2 commits June 8, 2026 11:17
- Replace sleep with SemaphoreStep in CustomLabelsIT to avoid flakiness
- Drop testInstanceNullCustomLabels (redundant)
- Suppress HARD_CODE_PASSWORD false positive on CustomLabelItem.key

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@EqualsAndHashCode
public class CustomLabelItem implements Describable<CustomLabelItem> {
@SuppressFBWarnings(value = "HARD_CODE_PASSWORD", justification = "not a password; this is a GCP label key")
private final String key;
mikecirioli and others added 3 commits June 8, 2026 15:09
…m.key

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@gbhat618

gbhat618 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

PR looks good to me, I have reviewed the new commits. I will allocate some 30min post lunch and if all is good, I will proceed to merge the PR. 🎉

@gbhat618

gbhat618 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Tested, works 🎉 . thank you @mikecirioli

image

@gbhat618 gbhat618 merged commit 531c476 into jenkinsci:develop Jun 9, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] No configuration to set GCE labels of the launched instance

4 participants