Sha256: c4e7c5823ee8ad186e1f3650b9e14ccb680de99d79c2b5952e2b2d302d761b7b

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require "json"

require_relative "base"
require_relative "../../../utils/git"

module Datadog
  module CI
    module Ext
      module Environment
        module Providers
          # Jenkins: https://www.jenkins.io/
          # Environment variables docs: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
          class Jenkins < Base
            def provider_name
              "jenkins"
            end

            def pipeline_id
              env["BUILD_TAG"]
            end

            def pipeline_name
              if (name = env["JOB_NAME"])
                name = name.gsub("/#{Datadog::CI::Utils::Git.normalize_ref(git_branch)}", "") if git_branch
                name = name.split("/").reject { |v| v.nil? || v.include?("=") }.join("/")
              end
              name
            end

            def pipeline_number
              env["BUILD_NUMBER"]
            end

            def pipeline_url
              env["BUILD_URL"]
            end

            def workspace_path
              env["WORKSPACE"]
            end

            def node_name
              env["NODE_NAME"]
            end

            def node_labels
              env["NODE_LABELS"] && env["NODE_LABELS"].split.to_json
            end

            def git_repository_url
              env["GIT_URL"] || env["GIT_URL_1"]
            end

            def git_commit_sha
              env["GIT_COMMIT"]
            end

            def git_branch_or_tag
              env["GIT_BRANCH"]
            end

            def ci_env_vars
              {
                "DD_CUSTOM_TRACE_ID" => env["DD_CUSTOM_TRACE_ID"]
              }.to_json
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datadog-ci-0.2.0 lib/datadog/ci/ext/environment/providers/jenkins.rb
datadog-ci-0.1.1 lib/datadog/ci/ext/environment/providers/jenkins.rb
datadog-ci-0.1.0 lib/datadog/ci/ext/environment/providers/jenkins.rb