Module: Jujube::Components::Triggers

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

#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.



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

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

#pollscm(interval) ⇒ Hash

Parameters:

  • interval (String)

    The polling interval, using cron syntax.

Returns:

  • (Hash)

    The specification for the component.



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

def pollscm(interval)
  {'pollscm' => interval}
end

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

Specify a pollurl trigger for a job.

This trigger requires support in jenkins-job-builder that has not yet been merged. See https://review.openstack.org/83524/ for the patch.

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.



38
39
40
# File 'lib/jujube/components/triggers.rb', line 38

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.



53
54
55
56
# File 'lib/jujube/components/triggers.rb', line 53

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.



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

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.



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

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.



71
72
73
74
# File 'lib/jujube/components/triggers.rb', line 71

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.



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

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