123456789_123456789_123456789_123456789_123456789_

Module: Gem::CIDetector

Relationships & Source Files
Defined in: lib/rubygems/ci_detector.rb

Constant Summary

  • ENV_DESCRIPTORS =

    For each CI, this env suffices to indicate that we’re on that CI’s containers. (A few of them only supply a CI_NAME variable, which is also nice). And if they set “CI” but we can’t tell which one they are, we also want to know that - a bare “ci” without another token tells us as much.

    # File 'lib/rubygems/ci_detector.rb', line 50
    {
      "TRAVIS" => "travis",
      "CIRCLECI" => "circle",
      "CIRRUS_CI" => "cirrus",
      "DSARI" => "dsari",
      "SEMAPHORE" => "semaphore",
      "JENKINS_URL" => "jenkins",
      "BUILDKITE" => "buildkite",
      "GO_SERVER_URL" => "go",
      "GITLAB_CI" => "gitlab",
      "GITHUB_ACTIONS" => "github",
      "TASKCLUSTER_ROOT_URL" => "taskcluster",
      "CI" => "ci",
    }.freeze
  • ENV_INDICATORS =

    Any of these being set is a reasonably reliable indicator that we are executing in a CI environment.

    # File 'lib/rubygems/ci_detector.rb', line 34
    [
      "CI",
      "CI_NAME",
      "CONTINUOUS_INTEGRATION",
      "BUILD_NUMBER",
      "CI_APP_ID",
      "CI_BUILD_ID",
      "CI_BUILD_NUMBER",
      "RUN_ID",
      "TASKCLUSTER_ROOT_URL",
    ].freeze

Class Attribute Summary

Class Method Summary

Class Attribute Details

.ci?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubygems/ci_detector.rb', line 65

def self.ci?
  ENV_INDICATORS.any? {|var| ENV.include?(var) }
end

Class Method Details

.ci_strings

[ GitHub ]

  
# File 'lib/rubygems/ci_detector.rb', line 69

def self.ci_strings
  matching_names = ENV_DESCRIPTORS.select {|env, _| ENV[env] }.values
  matching_names << ENV["CI_NAME"].downcase if ENV["CI_NAME"]
  matching_names.reject(&:empty?).sort.uniq
end