Skip to content

Draft: Make CI variables use aliasing for legacy names

What does this MR do and why?

We currently define duplicate variables in order to support legacy names:

app/models/concerns/ci/contextable.rb

    def predefined_variables
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        variables.append(key: 'CI_JOB_NAME', value: name)
        variables.append(key: 'CI_JOB_STAGE', value: stage)
        variables.append(key: 'CI_JOB_MANUAL', value: 'true') if action?
        variables.append(key: 'CI_PIPELINE_TRIGGERED', value: 'true') if trigger_request

        variables.append(key: 'CI_NODE_INDEX', value: self.options[:instance].to_s) if self.options&.include?(:instance)
        variables.append(key: 'CI_NODE_TOTAL', value: ci_node_total_value.to_s)

        # legacy variables
        variables.append(key: 'CI_BUILD_NAME', value: name)
        variables.append(key: 'CI_BUILD_STAGE', value: stage)
        variables.append(key: 'CI_BUILD_TRIGGERED', value: 'true') if trigger_request
        variables.append(key: 'CI_BUILD_MANUAL', value: 'true') if action?
      end
    end

This MR is to introduce alias to append another variable with the same value to the collection.

  def predefined_variables
      Gitlab::Ci::Variables::Collection.new.tap do |variables|
        variables.append(key: 'CI_JOB_NAME', value: name, alias: 'CI_BUILD_NAME')
        variables.append(key: 'CI_JOB_STAGE', value: stage, alias: 'CI_BUILD_STAGE')
        variables.append(key: 'CI_JOB_MANUAL', value: 'true', alias: 'CI_BUILD_MANUAL') if action?
        variables.append(key: 'CI_PIPELINE_TRIGGERED', value: 'true', alias: 'CI_BUILD_TRIGGERED') if trigger_request

        variables.append(key: 'CI_NODE_INDEX', value: self.options[:instance].to_s) if self.options&.include?(:instance)
        variables.append(key: 'CI_NODE_TOTAL', value: ci_node_total_value.to_s)
      end
    end

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #343087

Merge request reports

Loading