Module: Jujube::Components::Triggers

Extended by:
Macros
Included in:
Jujube::Components
Defined in:
lib/jujube/components/triggers.rb

Overview

Helper methods for creating trigger components.

pollurl Helpers collapse

pollurl Content Types collapse

Instance Method Summary collapse

Instance Method Details

#gitlab(options = {}) ⇒ Hash

Parameters:

  • options (Hash) (defaults to: {})

    The configuration options for the component.

Returns:

  • (Hash)

    The specification for the component.



15
# File 'lib/jujube/components/triggers.rb', line 15

standard_component :gitlab

#json(*paths) ⇒ Hash

Configure a JSON content check inside a #url specification of a #pollurl trigger.

Parameters:

  • paths (String...)

    Zero or more JSONPath expressions. Only changes to the parts of the JSON response that match one of the paths will trigger a build.

Returns:

  • (Hash)

    The specification for the content type.



103
104
105
# File 'lib/jujube/components/triggers.rb', line 103

def json(*paths)
  {"json" => paths}
end

#pollscm(options = {}) ⇒ Hash

Specify a pollscm trigger for a job.

This trigger requires jenkins-job-builder 1.3.0 or later.

See https://jenkins-job-builder.readthedocs.io/en/latest/triggers.html#triggers.pollscm.

Parameters:

  • options (Hash) (defaults to: {})

    The configuration options for the component.

Returns:

  • (Hash)

    The specification for the component.



26
# File 'lib/jujube/components/triggers.rb', line 26

standard_component :pollscm

#pollurl(options = {}) {|urls| ... } ⇒ Hash

Specify a pollurl trigger for a job.

See https://jenkins-job-builder.readthedocs.io/en/latest/triggers.html#triggers.pollurl.

pollurl can poll several URLs. Each URL specification is added in a nested configuration block using the #url method.

Examples:

job "pollurl-example" do |j|
  j.triggers << pollurl(cron: "CRON") do |urls|
    urls << url("URL", check_date: true) do |content|
      content << json("JSON_PATH1", "JSON_PATH2")
    end
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    Top-level options for configuring the component.

Yield Parameters:

  • urls (Array)

    An array to which nested URL specifications should be added by the block.

Returns:

  • (Hash)

    The specification for the component.



48
49
50
# File 'lib/jujube/components/triggers.rb', line 48

def pollurl(options = {}, &block)
  to_config("pollurl", nested_options(:urls, options, &block))
end

#reverse(options = {}) ⇒ Hash

Parameters:

  • options (Hash) (defaults to: {})

    The reverse project trigger options.

Options Hash (options):

  • :jobs (String, Array<String>)

    The jobs to watch. Note that jenkins-job-builder takes a string of comma-separated job names; Jujube does that formatting automatically, so pass in a String or Array of Strings.

  • :result (String)

    Build results to monitor for. One of 'success', 'unstable' or 'failure'.

Returns:

  • (Hash)

    The specification for the component.



63
64
65
66
# File 'lib/jujube/components/triggers.rb', line 63

def reverse(options = {})
  formatted_jobs = Array(options[:jobs]).join(", ")
  to_config("reverse", options.merge(jobs: formatted_jobs))
end

#simpleHash

Configure a simple content check inside a #url specification of a #pollurl trigger.

Returns:

  • (Hash)

    The specification for the content type.



93
94
95
# File 'lib/jujube/components/triggers.rb', line 93

def simple
  {"simple" => true}
end

#text(*regexes) ⇒ Hash

Configure a text content check inside a #url specification of a #pollurl trigger.

Parameters:

  • regexes (String...)

    Zero or more regular expressions. Only changes to the parts of the text response that match one of the regexes will trigger a build.

Returns:

  • (Hash)

    The specification for the content type.



123
124
125
# File 'lib/jujube/components/triggers.rb', line 123

def text(*regexes)
  {"text" => regexes}
end

#url(the_url, options = {}) {|content_types| ... } ⇒ Hash

Configure a URL to poll in a #pollurl component.

If you want to check for changes to the actual content returned from the URL, (the check-content setting), pass a block that configures the content-type specifications using one or more of #simple, #json, #xml, or #text.

Parameters:

  • the_url (String)

    The URL to monitor.

  • options (Hash) (defaults to: {})

    Top-level options for this URL.

Yield Parameters:

  • content_types (Array)

    An array to which nested content-type specifications should be added by the block.

Returns:

  • (Hash)

    The specification for the URL.



81
82
83
84
# File 'lib/jujube/components/triggers.rb', line 81

def url(the_url, options = {}, &block)
  options = {url: the_url}.merge!(options)
  canonicalize_options(nested_options(:check_content, options, &block))
end

#xml(*xpaths) ⇒ Hash

Configure an XML content check inside a #url specification of a #pollurl trigger.

Parameters:

  • xpaths (String...)

    Zero or more XPath expressions. Only changes to the parts of the XML response that match one of the xpaths will trigger a build.

Returns:

  • (Hash)

    The specification for the content type.



113
114
115
# File 'lib/jujube/components/triggers.rb', line 113

def xml(*xpaths)
  {"xml" => xpaths}
end