Skip to content

Add failed-pipeline trigger and enrich pipeline event metadata#1919

Open
damjanek wants to merge 1 commit into
jenkinsci:masterfrom
damjanek:feature/pipeline-event-enrichment
Open

Add failed-pipeline trigger and enrich pipeline event metadata#1919
damjanek wants to merge 1 commit into
jenkinsci:masterfrom
damjanek:feature/pipeline-event-enrichment

Conversation

@damjanek

Copy link
Copy Markdown

What this does

Makes GitLab pipeline (CI) event handling useful beyond "build only on success":

  • Trigger: new "Build on failed pipeline events" option, so failed pipelines
    no longer go unnoticed. The trigger now derives its allowed pipeline states
    from the success and failed flags independently.
  • Merge request resolution: new getCommitMergeRequests(projectId, sha)
    (GitLab v3/v4 /repository/commits/{sha}/merge_requests) so a pipeline event
    is associated with its MR; used to resolve MR title/iid/id and the target
    branch (MR target → project default branch → ref).
  • Env vars: richer build env exposing pipeline id/iid/source/url, commit
    message/title/author name/email/url, and project web URL / path-with-namespace.

Testing

Automated — added to PipelineHookTriggerHandlerImplTest:

  • pipeline_build_on_failed_event — a failed event triggers when enabled
  • pipeline_build_ignores_failed_when_not_configuredfailed ignored when disabled

Result: Tests run: 4, Failures: 0, Errors: 0 (Maven 3.9.9 / JDK 21); hpi packages cleanly.

Manual — deployed the built .hpi against a live GitLab:

  • Failed pipeline event triggers a build with the option on; only successful with it off.
  • MR-linked pipeline resolves the MR and builds the MR target branch.
  • Confirmed gitlabPipeline*, gitlabCommit*, gitlabProject* env vars populated.

The model/API additions have no dedicated unit tests as they are plain
payload/proxy mappings exercised by the above; let me know if you'd like the env-var mapping unit-tested.

Submitter checklist

  • Opening from a topic/feature/bugfix branch (not master)
  • PR title represents the desired changelog entry
  • Described what I did
  • Link to relevant issues
  • Link to relevant PRs
  • Provided tests demonstrating the feature

Make pipeline (CI) event handling useful beyond the previous
"build only on successful pipelines" behaviour.

Trigger:
- Add a "Build on failed pipeline events" option
  (triggerOnFailedPipelineEvent) alongside the existing successful-pipeline
  option, so failed pipelines no longer go unnoticed.
  PipelineHookTriggerHandlerFactory now derives the set of allowed pipeline
  states from both flags.

Merge request resolution:
- Add GitLabClient#getCommitMergeRequests(projectId, sha), backed by the
  GitLab v3/v4 "/repository/commits/{sha}/merge_requests" endpoint, so a
  pipeline event can be associated with its merge request. The handler uses
  this to resolve the MR title/iid/id and to derive the correct target
  branch (MR target branch, else project default branch, else the ref).

Build cause / environment variables:
- Expose richer pipeline metadata as build environment variables: pipeline
  id/iid/source/url, commit message/title/author name/email/url, and
  project web URL / path-with-namespace.
- Populate the pipeline CauseData from the project and commit payloads and
  use the source branch for branch/sourceBranch.

Webhook model:
- Add the payload fields required by the above: PipelineHook.commit and
  mergeRequest, Commit.title, Project.gitSshUrl / gitHttpUrl, and
  PipelineEventObjectAttributes.iid / source / url.

Tests:
- Cover triggering on failed pipeline events and that failed events are
  ignored when the option is disabled; add getCommitMergeRequests stubs.
@damjanek damjanek requested a review from a team as a code owner June 28, 2026 22:55
@github-actions github-actions Bot added the tests This PR adds/removes/updates test cases label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests This PR adds/removes/updates test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant