Class: Buildkite::Builder::Pipeline
- Inherits:
-
Object
- Object
- Buildkite::Builder::Pipeline
- Extended by:
- Forwardable
- Includes:
- Definition::Helper, LoggingUtils
- Defined in:
- lib/buildkite/builder/pipeline.rb
Constant Summary collapse
- PIPELINE_DEFINITION_FILE =
Pathname.new('pipeline.rb').freeze
Instance Attribute Summary collapse
-
#artifacts ⇒ Object
readonly
Returns the value of attribute artifacts.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#dsl ⇒ Object
readonly
Returns the value of attribute dsl.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root, logger: nil) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #to_h ⇒ Object
- #to_yaml ⇒ Object
- #upload ⇒ Object
Methods included from LoggingUtils
Methods included from Definition::Helper
Constructor Details
#initialize(root, logger: nil) ⇒ Pipeline
Returns a new instance of Pipeline.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/buildkite/builder/pipeline.rb', line 26 def initialize(root, logger: nil) @root = root @logger = logger || Logger.new(File::NULL) @artifacts = [] @dsl = Dsl.new(self) @extensions = ExtensionManager.new(self) @data = Data.new use(Extensions::Use) use(Extensions::Lib) use(Extensions::Env) use(Extensions::Notify) use(Extensions::Steps) use(Extensions::Plugins) use(Extensions::Agents) end |
Instance Attribute Details
#artifacts ⇒ Object (readonly)
Returns the value of attribute artifacts.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def artifacts @artifacts end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def data @data end |
#dsl ⇒ Object (readonly)
Returns the value of attribute dsl.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def dsl @dsl end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def extensions @extensions end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def logger @logger end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
19 20 21 |
# File 'lib/buildkite/builder/pipeline.rb', line 19 def root @root end |
Instance Method Details
#to_h ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/buildkite/builder/pipeline.rb', line 73 def to_h @pipeline_hash ||= begin results = benchmark("\nDone (%s)".color(:springgreen)) do dsl.instance_eval(&pipeline_definition) extensions.build end logger.info(results) # Build the pipeline definition from pipeline data. Pipelines::Helpers.sanitize(data.to_definition) end end |
#to_yaml ⇒ Object
85 86 87 |
# File 'lib/buildkite/builder/pipeline.rb', line 85 def to_yaml YAML.dump(to_h) end |
#upload ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/buildkite/builder/pipeline.rb', line 43 def upload # Generate the pipeline YAML first. contents = to_yaml upload_artifacts if data.steps.empty? logger.info "+++ :pipeline: No steps defined, skipping pipeline upload" else # Upload the pipeline. Tempfile.create(['pipeline', '.yml']) do |file| file.sync = true file.write(contents) logger.info "+++ :pipeline: Uploading pipeline" result = Buildkite::Pipelines::Command.pipeline(:upload, file.path) unless result.success? logger.info "Pipeline upload failed with #{result.stderr}, saving as artifact…" Buildkite::Pipelines::Command.artifact!(:upload, file.path) abort end end end logger.info "+++ :toolbox: Setting job meta-data to #{Buildkite.env.job_id.color(:yellow)}" Buildkite::Pipelines::Command.(:set, Builder..fetch(:job), Buildkite.env.step_id) end |