opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
72 stars 57 forks source link

Surprises in branchToEnvironmentMapping #975

Open filex opened 1 year ago

filex commented 1 year ago

Describe the bug

We have a fairly regular branch-mapping configured in our ODS 4.x project:

odsComponentPipeline(
  branchToEnvironmentMapping: [
    'develop': 'dev',
    'test': 'test',
    'eval': 'eval'
  ]
) { context ->
…

It "looks" like I had configured a simple 1:1 branch mapping.

But when I push a branch called develop-foobar two things happen:

  1. odsComponentStageBuildOpenShiftImage does not build the image:

    Skipping stage 'Build OpenShift Image (diseasemap-couper)' for branch 'develop-update' as it is not covered by: 'develop', 'test', 'eval'.

    (That is expected).

  2. odsComponentStageRolloutOpenShiftDeployment tries to rollout:

    [Deploy to OpenShift-diseasemap] **** STARTING stage 'Deploy to OpenShift' for component 'diseasemap' branch 'develop-foobar' ****

    That was unexpected.

Expected behavior

  1. Both functions must make the same decision (either run or don't)

  2. Both should decide against running because my branch map didn't indicate that I want "starts with" matches.

The second expectation is about the principle of least surprise.

This example is a bit more exciting:

  branchToEnvironmentMapping: [
    'develop': 'dev',
    'test': 'test',
    'feature/': 'dev'
  ]

The feature/ prefix contains a stop-character, which conveys gives the impression that multiple branches could be mapped.

setMostSpecificEnvironment looks like this may be a feature. So the testing-more-edge-cases branch would not trigger the test-env run but test-more-edge-cases would? That is surprising to me :)

Proposed Solution

Put aside any discussions about compatibility, we could change to only trigger the startsWith match if the key ends with an asterisk:

  branchToEnvironmentMapping: [
    'develop': 'dev',
    'test*': 'test',
    'feature/*': 'dev'
  ]

If key ends with * then remove * and go into if startsWith branch.

This would run test, testing-more and test-more, develop, feature/ and feature/foo but NOT develop-more and feature.

Affected version (please complete the following information):