Module: Rundeck::Client::Job

Included in:
Rundeck::Client
Defined in:
lib/rundeck/client/job.rb

Overview

Defines methods related to jobs.

Instance Method Summary collapse

Instance Method Details

#delete_job(id, options = {}) ⇒ Object

Delete a job

@TODO: What does this return?!

Examples:

Rundeck.delete_job('c07518ef-b697-4792-9a59-5b4f08855b67')

Parameters:

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Raises:



40
41
42
# File 'lib/rundeck/client/job.rb', line 40

def delete_job(id, options = {})
  delete("/job/#{id}", options)
end

#export_jobs(project, format = 'yaml', options = {}) ⇒ String

Export jobs to yaml or xml format

Examples:

Rundeck.export_jobs('project')

Parameters:

  • project (String)

    Project name

  • format (String) (defaults to: 'yaml')

    The export format. Either ‘yaml’ or ‘xml’

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

    A set of options passed directly to HTTParty. See rubydoc.info/gems/httparty/HTTParty/ClassMethods

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Returns:

  • (String)

    a string representation of the job in either xml or yaml

Raises:



90
91
92
93
94
95
96
97
98
99
# File 'lib/rundeck/client/job.rb', line 90

def export_jobs(project, format = 'yaml', options = {})
  unless format =~ /yaml|xml/
    fail Error::InvalidAttributes, 'format must be yaml or xml'
  end
  options[:query] = {} if options[:query].nil?
  options[:query].merge!('project' => project, 'format' => format)
  options[:format] = format

  get('/jobs/export', options)
end

#import_jobs(content, format = 'yaml', options = {}) ⇒ Rundeck::ObjectifiedHash

Import a job or multiple jobs

Examples:

job = "- id: c07518ef-b697-4792-9a59-5b4f08855b67
         project: Endeca
         ..."
Rundeck.import_jobs(job)
job = "<joblist>
         <job>
           <id>c07518ef-b697-4792-9a59-5b4f08855b67</id>
           ..."
Rundeck.import_jobs(job, 'xml')

Parameters:

  • content (String)

    The job definition(s) as yaml or xml

  • format (String) (defaults to: 'yaml')

    The import format. ‘yaml|xml’, defaults to ‘yaml’

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

    A set of options passed directly to HTTParty. See rubydoc.info/gems/httparty/HTTParty/ClassMethods

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Returns:

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rundeck/client/job.rb', line 65

def import_jobs(content, format = 'yaml', options = {})
  unless format =~ /yaml|xml/
    fail Error::InvalidAttributes, 'format must be yaml or xml'
  end
  options[:headers] = {} if options[:headers].nil?
  options[:headers].merge!(
      'Content-Type' => 'application/x-www-form-urlencoded')
  options[:body] = "xmlBatch=#{content}"
  options[:query] = {} if options[:query].nil?
  options[:query]['format'] = format

  objectify post('/jobs/import', options)['result']
end

#job(id, options = {}) ⇒ Rundeck::ObjectifiedHash

Gets a single job by id

Examples:

Rundeck.job(‘c07518ef-b697-4792-9a59-5b4f08855b67’)


Parameters:

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Returns:

Raises:



26
27
28
# File 'lib/rundeck/client/job.rb', line 26

def job(id, options = {})
  objectify get("/job/#{id}", options)['joblist']['job']
end

#jobs(project, options = {}) ⇒ Array<Rundeck::ObjectifiedHash>

Gets a list of jobs for a specific project.

Examples:

Rundeck.jobs('project')

Parameters:

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Returns:

Raises:



14
15
16
# File 'lib/rundeck/client/job.rb', line 14

def jobs(project, options = {})
  objectify get("/project/#{project}/jobs", options)['jobs']['job']
end