jenkinsci / datadog-plugin

A Jenkins plugin used to forward metrics, events, and service checks to an account at Datadog, automatically.
https://plugins.jenkins.io/datadog/
MIT License
30 stars 48 forks source link

Update job name calculation logic to correctly set names for builds that live inside folders #383

Closed nikita-tkachenko-datadog closed 7 months ago

nikita-tkachenko-datadog commented 7 months ago

Requirements for Contributing to this repository

What does this PR do?

Changes logic that calculates pipeline names. Previous version of the logic always retrieved the name from the job's parent. This was needed, because some jobs had names that are too specific (for multibranch projects the job name contained branch, for multiconfig projects the job name contained configuration values). This worked for regular projects, because the job parent was Jenkins, and its full name was empty, so the logic fell back to using job name.

However, this does not work for regular projects (or pipelines) that live inside folders. In this case the job's parent is the folder, and so the logic uses folder name as the pipeline's name. So all pipelines residing in a folder have the same name.

The logic was fixed to only use parent for name calculation if the project is either multi-branch or multi-config.

Below is the table that has multiple examples of different kinds of projects, along with the results of applying different name calculation logic to them. It can help to explain the rationale behind calculating pipeline name the way it is done now.

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

  | BuildData#getJobName | BuildData#getBaseJobName | envVars.get("JOB_NAME") | envVars.get("JOB_BASE_NAME") | run.getParent().getFullName() | run.getParent().getParent().getFullName() | run.getParent() | run.getParent().getParent() | run.getFullDisplayName() -- | -- | -- | -- | -- | -- | -- | -- | -- | -- freestyle-project | nikita-tkachenko-freestyle-project | nikita-tkachenko-freestyle-project | nikita-tkachenko-freestyle-project | nikita-tkachenko-freestyle-project | nikita-tkachenko-freestyle-project | "" | FreeStyleProject | Hudson | nikita-tkachenko-freestyle-project #1 pipeline | nikita-tkachenko-pipeline | nikita-tkachenko-pipeline | nikita-tkachenko-pipeline | nikita-tkachenko-pipeline | nikita-tkachenko-pipeline | "" | WorkflowJob | Hudson | nikita-tkachenko-pipeline #1 multi-config-project | nikita-tkachenko-multi-config-project | nikita-tkachenko-multi-config-project | nikita-tkachenko-multi-config-project | nikita-tkachenko-multi-config-project | nikita-tkachenko-multi-config-project | "" | MatrixProject | Hudson | nikita-tkachenko-multi-config-project #1 multi-config-project with axes | nikita-tkachenko-multi-config-project/other-user-config=abc,user-config=other-value | nikita-tkachenko-multi-config-project | nikita-tkachenko-multi-config-project/other-user-config=abc,user-config=other-value | other-user-config=abc,user-config=other-value | nikita-tkachenko-multi-config-project/other-user-config=abc,user-config=other-value | nikita-tkachenko-multi-config-project | MatrixConfiguration | MatrixProject | nikita-tkachenko-multi-config-project » abc,other-value #3 multibranch-pipeline | nikita-tkachenko-multi-branch-pipeline/main | nikita-tkachenko-multi-branch-pipeline | nikita-tkachenko-multi-branch-pipeline/main | "main" (name of the branch) | nikita-tkachenko-multi-branch-pipeline/main | nikita-tkachenko-multi-branch-pipeline | WorkflowJob | WorkflowMultiBranchProject | nikita-tkachenko-multi-branch-pipeline » main #1 pipeline in org folder | nikita-tkachenko-organization-folder/ci-test-project/main | nikita-tkachenko-organization-folder/ci-test-project | nikita-tkachenko-organization-folder/ci-test-project/main | "main" (name of the branch) | nikita-tkachenko-organization-folder/ci-test-project/main | nikita-tkachenko-organization-folder/ci-test-project | WorkflowJob | WorkflowMultiBranchProject | nikita-tkachenko-organization-folder » ci-test-project » main #1 freestyle-project in a folder | nikita-tkachenko-folder/nikita-tkachenko-nested-freestyle-project | nikita-tkachenko-folder | nikita-tkachenko-folder/nikita-tkachenko-nested-freestyle-project | nikita-tkachenko-nested-freestyle-project | nikita-tkachenko-folder/nikita-tkachenko-nested-freestyle-project | nikita-tkachenko-folder | FreeStyleProject | Folder | nikita-tkachenko-folder » nikita-tkachenko-nested-freestyle-project #1 pipeline in a folder | nikita-tkachenko-folder/nikita-tkachenko-nested-pipeline | nikita-tkachenko-folder | nikita-tkachenko-folder/nikita-tkachenko-nested-pipeline | nikita-tkachenko-nested-pipeline | nikita-tkachenko-folder/nikita-tkachenko-nested-pipeline | nikita-tkachenko-folder | WorkflowJob | Folder | nikita-tkachenko-folder » nikita-tkachenko-nested-pipeline #4 multi-config-project in a folder | nikita-tkachenko-folder/nikita-tkachenko-nested-multiconfig-project | nikita-tkachenko-folder | nikita-tkachenko-folder/nikita-tkachenko-nested-multiconfig-project | nikita-tkachenko-nested-multiconfig-project | nikita-tkachenko-folder/nikita-tkachenko-nested-multiconfig-project | nikita-tkachenko-folder | MatrixProject | Folder | nikita-tkachenko-folder » nikita-tkachenko-nested-multiconfig-project #1 multibranch-pipeline in a folder | nikita-tkachenko-folder/nikita-tkachenko-nested-multibranch-pipeline/main | nikita-tkachenko-folder/nikita-tkachenko-nested-multibranch-pipeline | nikita-tkachenko-folder/nikita-tkachenko-nested-multibranch-pipeline/main | "main" (name of the branch) | nikita-tkachenko-folder/nikita-tkachenko-nested-multibranch-pipeline/main | nikita-tkachenko-folder/nikita-tkachenko-nested-multibranch-pipeline | WorkflowJob | WorkflowMultiBranchProject | nikita-tkachenko-folder » nikita-tkachenko-nested-multibranch-pipeline » main #1 freestyle-project in a folder in a folder | nikita-tkachenko-folder/nikita-tkachenko-nested-folder/nikita-tkacheko-doubly-nested-freestyle-project | nikita-tkachenko-folder/nikita-tkachenko-nested-folder | nikita-tkachenko-folder/nikita-tkachenko-nested-folder/nikita-tkacheko-doubly-nested-freestyle-project | nikita-tkacheko-doubly-nested-freestyle-project | nikita-tkachenko-folder/nikita-tkachenko-nested-folder/nikita-tkacheko-doubly-nested-freestyle-project | nikita-tkachenko-folder/nikita-tkachenko-nested-folder | FreeStyleProject | Folder | nikita-tkachenko-folder » nikita-tkachenko-nested-folder » nikita-tkacheko-doubly-nested-freestyle-project #1

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)