Skip to content

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

Merged
nikita-tkachenko-datadog merged 22 commits into
masterfrom
nikita-tkachenko/job-name-calculation-for-folders
Jan 31, 2024
Merged

Update job name calculation logic to correctly set names for builds that live inside folders#383
nikita-tkachenko-datadog merged 22 commits into
masterfrom
nikita-tkachenko/job-name-calculation-for-folders

Conversation

@nikita-tkachenko-datadog

@nikita-tkachenko-datadog nikita-tkachenko-datadog commented Jan 30, 2024

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

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.

<style> </style>
  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)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@nikita-tkachenko-datadog nikita-tkachenko-datadog added the changelog/Fixed Fixed features results into a bug fix version bump label Jan 30, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog marked this pull request as ready for review January 30, 2024 21:28
Base automatically changed from nikita-tkachenko/memory-consumption-optimization to master January 31, 2024 09:38

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This class was formerly known as JobNameConfigurationParser, it's been renamed

{null, EMPTY_MAP},
{"", EMPTY_MAP},
{"jobName", EMPTY_MAP},
{"jobName/KEY1=VALUE1,KEY2=VALUE2", sampleMap},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we have removed some use cases where the jobName was followed by the branch. Is this expected?

@nikita-tkachenko-datadog nikita-tkachenko-datadog Jan 31, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I've examined the Jenkins Matrix Plugin docs, and could not find a way to include branch in the job name for multi-configuration projects.

It looks like the only way to have branch included in the job name is to create a Multibranch pipeline or an Organization Folder (and those cannot have parameters).

As far as I understood, historically the parser was being used both for parsing configurations and for extracting the "normalised" (i.e. without branch) job names. That seems to have been the case before the changes Albert made to job name calculation. That'd explain why it contained the logic for trimming branch.

Unless I'm missing something :)

@nikita-tkachenko-datadog
nikita-tkachenko-datadog merged commit a6c0b71 into master Jan 31, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog deleted the nikita-tkachenko/job-name-calculation-for-folders branch January 31, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants