Sha256: 12565e499b0b8c57234e1e8586a08aa48caff56433f52ea28b6b0b659f2b5b3c

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Buildkite
  module Builder
    module Extensions
      class Plugins < Extension
        attr_reader :manager

        dsl do
          def plugin(name, uri, default_attributes = {})
            context.extensions.find(Buildkite::Builder::Extensions::Plugins).manager.add(name, uri, default_attributes)
          end
        end

        def prepare
          @manager = PluginManager.new
        end

        def build
          context.data.steps.each(:command) do |step|
            next unless step.has?(:plugins)

            step.get(:plugins).map! do |plugin|
              resource, attributes = extract_resource_and_attributes(plugin)
              resource.is_a?(Symbol) ? manager.build(resource, attributes) : plugin
            end
          end

          context.data.pipelines.each do |pipeline|
            pipeline.data.steps.each(:command) do |step|
              next unless step.has?(:plugins)

              step.get(:plugins).map! do |plugin|
                resource, attributes = extract_resource_and_attributes(plugin)
                resource.is_a?(Symbol) ? manager.build(resource, attributes) : plugin
              end
            end
          end
        end

        private

        def extract_resource_and_attributes(plugin)
          [plugin.keys.first, plugin.values.first]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildkite-builder-3.9.0 lib/buildkite/builder/extensions/plugins.rb