Skip to content

Improve branch selection logic for docs-test hugo job

What does this MR do?

Two fixes for the docs-test hugo CI job. This job needs to checkout a copy of the Docs website that matches the version of the MR or branch that a change to Chart is targeting, and it was missing handling for two scenarios:

  1. If Chart cuts a release branch and then needs to merge a docs change to it before the Docs site's corresponding release branch exists, we need to fallback to the Docs site's main branch for the Hugo build job. If we attempt to checkout a non-existent docs site branch, the job incorrectly fails.

    This can happen shortly before a release since the Docs site release branch is cut on release day, but other projects cut their branches earlier.

    Same fix in gitlab: gitlab-org/gitlab!204420 (merged)

  2. Branch selection logic was also wrong for commits that run outside of MRs, like a direct push to a branch with a security fix, which happened here. This was because the original code only checked against CI_MERGE_REQUEST_TARGET_BRANCH_NAME, which is only available in merge request pipelines. When the job ran for other pipeline types (like PROTECTED_TEST_PIPELINE in that case), this variable was empty, so the branch detection logic failed and it always defaulted to the (incorrect) main docs branch.

    Similar fix in gitlab: gitlab-org/gitlab!200118 (merged)

Test jobs

I tested behavior for 9-2-stable by adjusting this MR to target it:

MR target branch Expected Docs branch Example
9-2-stable 18.2 https://gitlab.com/gitlab-org/charts/gitlab/-/jobs/11584092503
master main https://gitlab.com/gitlab-org/charts/gitlab/-/jobs/11583699479

Related issues

gitlab-org/technical-writing/docs-gitlab-com#450 (closed)

Author checklist

For general guidance, please follow our Contributing guide.

Required

For anything in this list which will not be completed, please provide a reason in the MR discussion.

  • Merge Request Title and Description are up to date, accurate, and descriptive.
  • MR targeting the appropriate branch.
  • MR has a green pipeline.
  • Documentation created/updated.
  • Tests added/updated, and test plan for scenarios not covered by automated tests.
  • Equivalent MR/issue for omnibus-gitlab opened.

Reviewers checklist

Edited by João Alexandre Cunha

Merge request reports

Loading