Skip to content

Introduce CI_PROJECT_TITLE as predefined variable

Nejc Habjan requested to merge nejc/gitlab:add-ci-project-title-variable into master

What does this MR do?

This introduces a CI_PROJECT_TITLE predefined environment variable for the project name as displayed in the GitLab web interface.

This closes #18190 (closed) while keeping backwards compatibility for CI_PROJECT_NAME.

Context

Use cases are obvious (Pages, auto-generated docs, test report titles, etc). A previous MR (gitlab-foss!15826 (closed)) suggested changing that variable, but that would break all kinds of things, from shell scripts with unquoted variables, to integrations based on GitLab examples and even gitlab pipelines (see grep output of gitlab repo below). As noted in gitlab-foss!15826 (comment 51254498), adding a new variable instead is an option.

I was thinking of suitable options, but then I found that app/models/project.rb already has an alias for project.title. Why not reuse it, unless I'm missing something here? I'm not super familiar with Ruby yet. I also changed the docs a bit to reflect that CI_PROJECT_NAME refers to the repo name/URL segment, while CI_PROJECT_TITLE is the human-readable name in the UI.

@markglenfletcher @bikebilly you were in the original issue & MR discussions, what do you think?

Note: I actually think that CI_PROJECT_NAME isn't that bad - when I do git clone https://gitlab.com/gitlab-org/gitlab-foss, my local project is named gitlab-foss, not GitLab FOSS. If anything, the "path" wording in the frontend is confusing as it can imply the full path. "Project title" and "Repository name" would maybe make more sense even in the frontend in place of "Project Name" and "Path" - this is even used in the Path section in the settings:

Be careful. Renaming a project's repository can have unintended side effects.

Some more reasoning for not changing CI_PROJECT_NAME:

~/gitlab$ grep -R -v CI_PROJECT_NAMESPACE | grep CI_PROJECT_NAME

doc/development/pipelines.md:- `KNAPSACK_RSPEC_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/rspec_report-master.json`
doc/development/pipelines.md:- `EE_KNAPSACK_RSPEC_SUITE_REPORT_PATH: knapsack/${CI_PROJECT_NAME}/rspec_report-master-ee.json`
doc/ci/ci_cd_for_external_repos/bitbucket_integration.md:       echo "Setting BITBUCKET_REPOSITORY to $CI_PROJECT_NAME"
doc/ci/ci_cd_for_external_repos/bitbucket_integration.md:       BITBUCKET_REPOSITORY=$CI_PROJECT_NAME
doc/ci/large_repositories/index.md:  GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_NAME
doc/ci/large_repositories/index.md:    "GIT_CLONE_PATH=$CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_NAME"
doc/ci/variables/predefined_variables.md:| `CI_PROJECT_NAME`                       | 8.10   | 0.5    | The project name that is currently being built (actually it is project folder name) |
doc/ci/variables/README.md:export CI_PROJECT_NAME="gitlab-foss"
doc/ci/variables/README.md:++ export CI_PROJECT_NAME=ci-debug-trace
doc/ci/variables/README.md:++ CI_PROJECT_NAME=ci-debug-trace
app/models/project.rb:      .append(key: 'CI_PROJECT_NAME', value: path)
.gitlab/ci/setup.gitlab-ci.yml:      - $CI_PROJECT_NAME == "gitlab-foss"
.gitlab/ci/setup.gitlab-ci.yml:      - $CI_PROJECT_NAME == "gitlab-ce"  # Support former project name for forks/mirrors
.gitlab/ci/setup.gitlab-ci.yml:      - $CI_PROJECT_NAME == "gitlabhq"  # Support former project name for dev
.gitlab/ci/review.gitlab-ci.yml:    - export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/review-qa-all_master_report.json
.gitlab/ci/global.gitlab-ci.yml:      - $CI_PROJECT_NAME == "gitlab"
.gitlab/ci/global.gitlab-ci.yml:      - $CI_PROJECT_NAME == "gitlab-ee"  # Support former project name for forks/mirrors
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    - oc project "$CI_PROJECT_NAME-$CI_PROJECT_ID" 2> /dev/null || oc new-project "$CI_PROJECT_NAME-$CI_PROJECT_ID"
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    APP_HOST: $CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    url: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    APP_HOST: $CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    url: http://$CI_PROJECT_NAME-staging.$OPENSHIFT_DOMAIN
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    APP_HOST: $CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
lib/gitlab/ci/templates/OpenShift.gitlab-ci.yml:    url: http://$CI_PROJECT_NAME.$OPENSHIFT_DOMAIN
lib/gitlab/danger/helper.rb:        %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?('../../ee')
scripts/build_assets_image:if [[ "${CI_PROJECT_NAME}" == "gitlab" ]] || [[ "${CI_PROJECT_NAME}" == "gitlab-ee" ]]
scripts/review_apps/automated_cleanup.rb:    %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME'])
scripts/trigger-build:    %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME'])
scripts/trigger-build-docs:  case ENV["CI_PROJECT_NAME"]
spec/models/ci/bridge_spec.rb:        CI_PROJECT_ID CI_PROJECT_NAME CI_PROJECT_PATH
spec/models/ci/build_spec.rb:          { key: 'CI_PROJECT_NAME', value: project.path, public: true, masked: false },
spec/models/ci/build_spec.rb:            let(:url) { 'http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG' }
spec/lib/gitlab/ci/build/policy/variables_spec.rb:    pipeline.variables.build(key: 'CI_PROJECT_NAME', value: '')
spec/lib/gitlab/ci/build/policy/variables_spec.rb:      policy = described_class.new(['$CI_PROJECT_NAME'])
spec/lib/gitlab/danger/helper_spec.rb:    it 'returns true if CI_PROJECT_NAME if set to gitlab' do
spec/lib/gitlab/danger/helper_spec.rb:      stub_env('CI_PROJECT_NAME', 'gitlab')
spec/lib/gitlab/danger/helper_spec.rb:    it 'delegates to CHANGELOG-EE.md existence if CI_PROJECT_NAME is set to something else' do
spec/lib/gitlab/danger/helper_spec.rb:      stub_env('CI_PROJECT_NAME', 'something else')
spec/lib/gitlab/danger/helper_spec.rb:      stub_env('CI_PROJECT_NAME', nil)
spec/lib/gitlab/danger/helper_spec.rb:      stub_env('CI_PROJECT_NAME', nil)
spec/fixtures/trace/sample_trace:$ export KNAPSACK_REPORT_PATH=knapsack/${CI_PROJECT_NAME}/${JOB_NAME[0]}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json

Does this MR meet the acceptance criteria?

Conformity

Performance and Testing

Edited by 🤖 GitLab Bot 🤖

Merge request reports