jenkins_api_client 1.4.5 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/jenkins_api_client.gemspec +15 -136
  3. data/lib/jenkins_api_client/version.rb +2 -2
  4. metadata +6 -180
  5. data/.gitignore +0 -41
  6. data/.jenkins.yml +0 -9
  7. data/.travis.yml +0 -15
  8. data/CHANGELOG.md +0 -391
  9. data/CONTRIBUTORS.md +0 -3
  10. data/Gemfile +0 -20
  11. data/LICENCE +0 -21
  12. data/README.md +0 -454
  13. data/Rakefile +0 -107
  14. data/Vagrantfile +0 -83
  15. data/config/login.yml.example +0 -27
  16. data/jenkins_api_client_class_diagram.png +0 -0
  17. data/scripts/login_with_irb.rb +0 -54
  18. data/scripts/login_with_pry.rb +0 -54
  19. data/spec/func_tests/client_spec.rb +0 -109
  20. data/spec/func_tests/job_spec.rb +0 -669
  21. data/spec/func_tests/node_spec.rb.pending +0 -217
  22. data/spec/func_tests/plugin_spec.rb +0 -148
  23. data/spec/func_tests/spec_helper.rb +0 -41
  24. data/spec/func_tests/system_spec.rb +0 -84
  25. data/spec/func_tests/user_spec.rb +0 -49
  26. data/spec/func_tests/view_spec.rb +0 -276
  27. data/spec/unit_tests/build_queue_spec.rb +0 -152
  28. data/spec/unit_tests/client_spec.rb +0 -471
  29. data/spec/unit_tests/fake_http_response.rb +0 -9
  30. data/spec/unit_tests/fixtures/files/available_plugins.json +0 -1
  31. data/spec/unit_tests/fixtures/files/computer_sample.xml +0 -17
  32. data/spec/unit_tests/fixtures/files/installed_plugins.json +0 -1
  33. data/spec/unit_tests/fixtures/files/job_sample.xml +0 -16
  34. data/spec/unit_tests/fixtures/files/updatable_plugins.json +0 -1
  35. data/spec/unit_tests/job_spec.rb +0 -783
  36. data/spec/unit_tests/node_spec.rb +0 -342
  37. data/spec/unit_tests/plugin_settings/colllection_spec.rb +0 -62
  38. data/spec/unit_tests/plugin_settings/hipchat_spec.rb +0 -44
  39. data/spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb +0 -31
  40. data/spec/unit_tests/plugin_spec.rb +0 -165
  41. data/spec/unit_tests/spec_helper.rb +0 -19
  42. data/spec/unit_tests/system_spec.rb +0 -76
  43. data/spec/unit_tests/user_spec.rb +0 -144
  44. data/spec/unit_tests/view_spec.rb +0 -149
  45. data/travis/hudson.model.UpdateCenter.xml +0 -7
  46. data/travis/jenkins_config.xml +0 -63
  47. data/travis/jenkins_config_with_crumb.xml +0 -67
  48. data/travis/setup.sh +0 -23
  49. data/travis/setup_crumb.sh +0 -11
  50. data/travis/spec.yml +0 -14
  51. data/travis/user_config.xml +0 -29
data/Rakefile DELETED
@@ -1,107 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'jenkins_api_client/version'
4
- require 'rake'
5
- require 'jeweler'
6
- require 'yard'
7
-
8
- Jeweler::Tasks.new do |gemspec|
9
- gemspec.name = 'jenkins_api_client'
10
- gemspec.version = JenkinsApi::Client::VERSION
11
- gemspec.platform = Gem::Platform::RUBY
12
- gemspec.date = Time.now.utc.strftime("%Y-%m-%d")
13
- gemspec.require_paths = ["lib"]
14
- gemspec.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
15
- gemspec.files = `git ls-files`.split("\n")
16
- gemspec.extra_rdoc_files = ['CHANGELOG.rdoc', 'LICENSE', 'README.rdoc']
17
- gemspec.authors = [ 'Kannan Manickam' ]
18
- gemspec.email = [ 'arangamani.kannan@gmail.com' ]
19
- gemspec.homepage = 'https://github.com/arangamani/jenkins_api_client'
20
- gemspec.summary = 'Jenkins JSON API Client'
21
- gemspec.description = %{
22
- This is a simple and easy-to-use Jenkins Api client with features focused on
23
- automating Job configuration programaticaly and so forth}
24
- gemspec.test_files = `git ls-files -- {spec}/*`.split("\n")
25
- gemspec.required_ruby_version = '>= 1.9.2'
26
- gemspec.rubygems_version = '1.8.17'
27
- end
28
-
29
- require 'rspec/core'
30
- require 'rspec/core/rake_task'
31
- RSpec::Core::RakeTask.new(:unit_tests) do |spec|
32
- spec.pattern = FileList['spec/unit_tests/*_spec.rb']
33
- spec.rspec_opts = ['--color', '--format documentation']
34
- end
35
-
36
- RSpec::Core::RakeTask.new(:func_tests) do |spec|
37
- spec.pattern = FileList['spec/func_tests/*_spec.rb']
38
- spec.rspec_opts = ['--color', '--format documentation']
39
- end
40
-
41
- RSpec::Core::RakeTask.new(:test) do |spec|
42
- spec.pattern = FileList['spec/*/*.rb']
43
- spec.rspec_opts = ['--color', '--format documentation']
44
- end
45
-
46
- YARD::Config.load_plugin 'thor'
47
- YARD::Rake::YardocTask.new do |t|
48
- t.files = ['lib/**/*.rb', 'lib/**/**/*.rb']
49
- end
50
-
51
- namespace :doc do
52
- # This task requires that graphviz is installed locally. For more info:
53
- # http://www.graphviz.org/
54
- desc "Generates the class diagram using the yard generated dot file"
55
- task :generate_class_diagram do
56
- puts "Generating the dot file..."
57
- `yard graph --file jenkins_api_client.dot`
58
- puts "Generating class diagram from the dot file..."
59
- `dot jenkins_api_client.dot -Tpng -o jenkins_api_client_class_diagram.png`
60
- end
61
-
62
- desc "Applies Google Analytics tracking script to all generated html files"
63
- task :apply_google_analytics do
64
- files = Dir.glob("**/*.html")
65
-
66
- string_to_replace = "</body>"
67
- string_to_replace_with = <<-EOF
68
- <script type="text/javascript">
69
- var _gaq = _gaq || [];
70
- _gaq.push(['_setAccount', 'UA-37519629-2']);
71
- _gaq.push(['_trackPageview']);
72
-
73
- (function() {
74
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
75
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
76
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
77
- })();
78
- </script>
79
- </body>
80
- EOF
81
-
82
- files.each do |html_file|
83
- puts "Processing file: #{html_file}"
84
- contents = ""
85
- # Read the file contents
86
- file = File.open(html_file)
87
- file.each { |line| contents << line }
88
- file.close
89
-
90
- # If the file already has google analytics tracking info, skip it.
91
- if contents.include?(string_to_replace_with)
92
- puts "Skipped..."
93
- next
94
- end
95
-
96
- # Apply google analytics tracking info to the html file
97
- contents.gsub!(string_to_replace, string_to_replace_with)
98
-
99
- # Write the contents with the google analytics info to the file
100
- file = File.open(html_file, "w")
101
- file.write(contents)
102
- file.close
103
- end
104
- end
105
- end
106
-
107
- task :default => [:unit_tests]
data/Vagrantfile DELETED
@@ -1,83 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- Vagrant.configure("2") do |config|
5
- # All Vagrant configuration is done here. The most common configuration
6
- # options are documented and commented below. For a complete reference,
7
- # please see the online documentation at vagrantup.com.
8
-
9
- config.vm.hostname = "jenkins-api-client"
10
-
11
- # Every Vagrant virtual environment requires a box to build off of.
12
- config.vm.box = "opscode-ubuntu-12.04"
13
-
14
- # The url from where the 'config.vm.box' box will be fetched if it
15
- # doesn't already exist on the user's system.
16
- config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box"
17
-
18
- # Assign this VM to a host-only network IP, allowing you to access it
19
- # via the IP. Host-only networks can talk to the host machine as well as
20
- # any other machines on the same network, but cannot be accessed (through this
21
- # network interface) by any external networks.
22
- config.vm.network :private_network, ip: "33.33.33.10"
23
-
24
- # Create a public network, which generally matched to bridged network.
25
- # Bridged networks make the machine appear as another physical device on
26
- # your network.
27
-
28
- # config.vm.network :public_network
29
-
30
- # Create a forwarded port mapping which allows access to a specific port
31
- # within the machine from a port on the host machine. In the example below,
32
- # accessing "localhost:8080" will access port 80 on the guest machine.
33
-
34
- # Share an additional folder to the guest VM. The first argument is
35
- # the path on the host to the actual folder. The second argument is
36
- # the path on the guest to mount the folder. And the optional third
37
- # argument is a set of non-required options.
38
- # config.vm.synced_folder "../data", "/vagrant_data"
39
-
40
- # Provider-specific configuration so you can fine-tune various
41
- # backing providers for Vagrant. These expose provider-specific options.
42
- # Example for VirtualBox:
43
- #
44
- # config.vm.provider :virtualbox do |vb|
45
- # # Don't boot with headless mode
46
- # vb.gui = true
47
- #
48
- # # Use VBoxManage to customize the VM. For example to change memory:
49
- # vb.customize ["modifyvm", :id, "--memory", "1024"]
50
- # end
51
- #
52
- # View the documentation for the provider you're using for more
53
- # information on available options.
54
-
55
- # The path to the Berksfile to use with Vagrant Berkshelf
56
- # config.berkshelf.berksfile_path = "./Berksfile"
57
-
58
- # Enabling the Berkshelf plugin. To enable this globally, add this configuration
59
- # option to your ~/.vagrant.d/Vagrantfile file
60
- #config.berkshelf.enabled = true
61
-
62
- # An array of symbols representing groups of cookbook described in the Vagrantfile
63
- # to exclusively install and copy to Vagrant's shelf.
64
- # config.berkshelf.only = []
65
-
66
- # An array of symbols representing groups of cookbook described in the Vagrantfile
67
- # to skip installing and copying to Vagrant's shelf.
68
- # config.berkshelf.except = []
69
-
70
- config.vm.synced_folder ".", "/opt/jenkins_api_client"
71
-
72
- config.vm.provision :shell, :inline =>
73
- " sudo apt-get update;" +
74
- " sudo apt-get install -y git ruby1.9.1-full rubygems libxslt-dev libxml2-dev;" +
75
- " cd /opt/jenkins_api_client;" +
76
- " ls -lrt;" +
77
- " ruby1.9.1 --version;" +
78
- " sudo gem1.9.1 install bundler;" +
79
- " bundle install;" +
80
- " travis/setup.sh;" +
81
- " bundle exec rake unit_tests;" +
82
- " bundle exec rake func_tests"
83
- end
@@ -1,27 +0,0 @@
1
- # The Jenkins server and login information can be stored in a YAML file like this
2
- # so we don't have to pass in the parameters every we login to the server
3
- # through this API client.
4
-
5
- # This file contains the following four parameters
6
-
7
- # The IP address of the Jenkins CI Server
8
-
9
- :server_ip: 0.0.0.0
10
-
11
- # The port number on which the Jenkins listens on. The default is 8080
12
-
13
- :server_port: 8080
14
-
15
- # If there is a web server routing your Jenkins requests you might need this
16
-
17
- :jenkins_path: ""
18
-
19
- # The username and password to authenticate to the server
20
-
21
- :username: my_username
22
-
23
- :password: my_password
24
-
25
- # The private key file for Jenkins CLI authentication
26
- # remember to upload the public key to http://#{server_ip}:#{server_port}/user/#{my_username}/configure
27
- :identity_file: ~/.ssh/id_rsa
Binary file
@@ -1,54 +0,0 @@
1
- # This script provides an easier way to login to Jenkins server API.
2
- # It logs you in with the credentials and server details you proided and then
3
- # starts an IRB session so you can interactively play with the API.
4
-
5
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
6
- require 'jenkins_api_client'
7
- require 'yaml'
8
- require 'irb'
9
-
10
- def prompt_for_username
11
- get_from_stdin("Username: ", false)
12
- end
13
-
14
- def prompt_for_password
15
- get_from_stdin("Password: ", true)
16
- end
17
-
18
- def get_from_stdin(prompt, mask = false)
19
- $stdout.write(prompt)
20
-
21
- begin
22
- Kernel::system "stty -echo" if mask == true
23
- ret = gets.chomp!
24
- ensure
25
- if mask == true
26
- Kernel::system "stty echo"
27
- puts ""
28
- end
29
- end
30
-
31
- ret
32
- end
33
-
34
- if ARGV.empty?
35
- config_file = '~/.jenkins_api_client/login.yml'
36
- else
37
- config_file = ARGV.shift
38
- end
39
-
40
- begin
41
- client_opts = Hash[YAML.load_file(File.expand_path(config_file)).map { | (k,v) | [k.to_sym, v]} ]
42
-
43
- unless client_opts.has_key?(:username)
44
- client_opts[:username] = prompt_for_username()
45
- end
46
- unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)
47
- client_opts[:password] = prompt_for_password()
48
- end
49
-
50
- @client = JenkinsApi::Client.new(client_opts)
51
- puts "logged-in to the Jenkins API, use the '@client' variable to use the client"
52
- end
53
-
54
- IRB.start
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This script provides an easier way to login to Jenkins server API.
3
- # It logs you in with the credentials and server details you proided and then
4
- # starts an IRB session so you can interactively play with the API.
5
-
6
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
7
- require 'jenkins_api_client'
8
- require 'yaml'
9
- require 'pry'
10
-
11
- def prompt_for_username
12
- get_from_stdin("Username: ", false)
13
- end
14
-
15
- def prompt_for_password
16
- get_from_stdin("Password: ", true)
17
- end
18
-
19
- def get_from_stdin(prompt, mask = false)
20
- $stdout.write(prompt)
21
-
22
- begin
23
- Kernel::system "stty -echo" if mask == true
24
- ret = gets.chomp!
25
- ensure
26
- if mask == true
27
- Kernel::system "stty echo"
28
- puts ""
29
- end
30
- end
31
-
32
- ret
33
- end
34
-
35
- if ARGV.empty?
36
- config_file = '~/.jenkins_api_client/spec.yml'
37
- else
38
- config_file = ARGV.shift
39
- end
40
-
41
- begin
42
- client_opts = YAML.load_file(File.expand_path(config_file))
43
- unless client_opts.has_key?(:username)
44
- client_opts[:username] = prompt_for_username()
45
- end
46
- unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)
47
- client_opts[:password] = prompt_for_password()
48
- end
49
-
50
- @client = JenkinsApi::Client.new(client_opts)
51
- puts "logged-in to the Jenkins API, use the '@client' variable to use the client"
52
- end
53
-
54
- Pry.start
@@ -1,109 +0,0 @@
1
- #
2
- # Specifying JenkinsApi::Client class capabilities
3
- # Author: Kannan Manickam <arangamani.kannan@gmail.com>
4
- #
5
-
6
- require File.expand_path('../spec_helper', __FILE__)
7
- require 'yaml'
8
-
9
- describe JenkinsApi::Client do
10
- context "Given valid credentials and server information are given" do
11
- before(:all) do
12
- @creds_file = '~/.jenkins_api_client/spec.yml'
13
- # Grabbing just the server IP in a variable so we can check
14
- # for wrong credentials
15
- @server_ip = YAML.load_file(
16
- File.expand_path(@creds_file, __FILE__)
17
- )[:server_ip]
18
- begin
19
- @client = JenkinsApi::Client.new(
20
- YAML.load_file(File.expand_path(@creds_file, __FILE__))
21
- )
22
- rescue Exception => e
23
- puts "WARNING: Credentials are not set properly."
24
- puts e.message
25
- end
26
- end
27
-
28
- describe "InstanceMethods" do
29
-
30
- describe "#initialize" do
31
- it "Should be able to initialize with valid credentials" do
32
- client1 = JenkinsApi::Client.new(
33
- YAML.load_file(File.expand_path(@creds_file, __FILE__))
34
- )
35
- client1.class.should == JenkinsApi::Client
36
- end
37
-
38
- it "Should accept a YAML argument when creating a new client" do
39
- client3 = JenkinsApi::Client.new(
40
- YAML.load_file(File.expand_path(@creds_file, __FILE__))
41
- )
42
- client3.class.should == JenkinsApi::Client
43
- end
44
-
45
- it "Should fail if wrong credentials are given" do
46
- client2 = JenkinsApi::Client.new(
47
- :server_ip => @server_ip,
48
- :username => 'stranger',
49
- :password => 'hacked',
50
- :log_location => '/dev/null'
51
- )
52
- expect(
53
- lambda { client2.job.list_all }
54
- ).to raise_error(JenkinsApi::Exceptions::Unauthorized)
55
- end
56
- end
57
- describe "#get_jenkins_version" do
58
- it "Should the jenkins version" do
59
- @client.get_jenkins_version.class.should == String
60
- end
61
- end
62
-
63
- describe "#get_hudson_version" do
64
- it "Should get the hudson version" do
65
- @client.get_hudson_version.class.should == String
66
- end
67
- end
68
-
69
- describe "#exec_script" do
70
- it "Should execute the provided groovy script" do
71
- @client.exec_script('println("hi")').should == "hi\n"
72
- end
73
- end
74
- end
75
-
76
- describe "SubClassAccessorMethods" do
77
- describe "#job" do
78
- it "Should return a job object on call" do
79
- @client.job.class.should == JenkinsApi::Client::Job
80
- end
81
- end
82
-
83
- describe "#node" do
84
- it "Should return a node object on call" do
85
- @client.node.class.should == JenkinsApi::Client::Node
86
- end
87
- end
88
-
89
- describe "#view" do
90
- it "Should return a view object on call" do
91
- @client.view.class.should == JenkinsApi::Client::View
92
- end
93
- end
94
-
95
- describe "#system" do
96
- it "Should return a system object on call" do
97
- @client.system.class.should == JenkinsApi::Client::System
98
- end
99
- end
100
-
101
- describe "#queue" do
102
- it "Should return a build queue object on call" do
103
- @client.queue.class.should == JenkinsApi::Client::BuildQueue
104
- end
105
- end
106
- end
107
-
108
- end
109
- end
@@ -1,669 +0,0 @@
1
- #
2
- # Specifying JenkinsApi::Client::Job class capabilities
3
- # Author: Kannan Manickam <arangamani.kannan@gmail.com>
4
- #
5
-
6
- require File.expand_path('../spec_helper', __FILE__)
7
- require 'yaml'
8
-
9
- describe JenkinsApi::Client::Job do
10
- context "With properly initialized client" do
11
- before(:all) do
12
- @helper = JenkinsApiSpecHelper::Helper.new
13
- @creds_file = '~/.jenkins_api_client/spec.yml'
14
- @creds = YAML.load_file(File.expand_path(@creds_file, __FILE__))
15
- @job_name_prefix = 'awesome_rspec_test_job'
16
- @filter = "^#{@job_name_prefix}.*"
17
- @job_name = ''
18
- @valid_post_responses = [200, 201, 302]
19
- begin
20
- @client = JenkinsApi::Client.new(@creds)
21
- rescue Exception => e
22
- puts "WARNING: Credentials are not set properly."
23
- puts e.message
24
- end
25
- # Creating 10 jobs to run the spec tests on
26
- begin
27
- 10.times do |num|
28
- xml = @helper.create_job_xml
29
- job = "#{@job_name_prefix}_#{num}"
30
- @job_name = job if num == 0
31
- @client.job.create(job, xml).to_i.should == 200
32
- end
33
- rescue Exception => e
34
- puts "WARNING: Can't create jobs for preparing to spec tests"
35
- end
36
- end
37
-
38
- describe "InstanceMethods" do
39
-
40
- describe "#initialize" do
41
- it "Initializes without any exception" do
42
- expect(
43
- lambda { job = JenkinsApi::Client::Job.new(@client) }
44
- ).not_to raise_error
45
- end
46
- it "Raises an error if a reference of client is not passed" do
47
- expect(
48
- lambda { job = JenkinsApi::Client::Job.new() }
49
- ).to raise_error
50
- end
51
- end
52
-
53
- describe "#create" do
54
- it "Should be able to create a job by getting an xml" do
55
- xml = @helper.create_job_xml
56
- name = "qwerty_nonexistent_job"
57
- @valid_post_responses.should include(
58
- @client.job.create(name, xml).to_i
59
- )
60
- @client.job.list(name).include?(name).should be_true
61
- end
62
- it "Should raise proper exception when the job already exists" do
63
- xml = @helper.create_job_xml
64
- name = "the_duplicate_job"
65
- @valid_post_responses.should include(
66
- @client.job.create(name, xml).to_i
67
- )
68
- @client.job.list(name).include?(name).should be_true
69
- expect(
70
- lambda { @client.job.create(name, xml) }
71
- ).to raise_error(JenkinsApi::Exceptions::JobAlreadyExists)
72
- @valid_post_responses.should include(
73
- @client.job.delete(name).to_i
74
- )
75
- end
76
- end
77
-
78
- describe "#create_freestyle" do
79
-
80
- def test_and_validate(name, params, config_line = nil)
81
- @valid_post_responses.should include(
82
- @client.job.create_freestyle(params).to_i
83
- )
84
- @client.job.list(name).include?(name).should be_true
85
- # Test for the existense of the given line in the config.xml of the
86
- # job created
87
- unless config_line.nil?
88
- config = @client.job.get_config(name)
89
- config.should =~ /#{config_line}/
90
- end
91
- @valid_post_responses.should include(
92
- @client.job.delete(name).to_i
93
- )
94
- @client.job.list(name).include?(name).should be_false
95
- end
96
-
97
- it "Should create a freestyle job with just name" do
98
- name = "test_job_name_using_params"
99
- params = {
100
- :name => name
101
- }
102
- test_and_validate(name, params)
103
- end
104
- it "Should create a freestyle job with shell command" do
105
- name = "test_job_using_params_shell"
106
- params = {
107
- :name => name,
108
- :shell_command => "echo this is a free style project"
109
- }
110
- test_and_validate(
111
- name,
112
- params,
113
- "<command>echo this is a free style project</command>"
114
- )
115
- end
116
- it "Should create a freestyle job with Git SCM provider" do
117
- name = "test_job_with_git_scm"
118
- params = {
119
- :name => name,
120
- :scm_provider => "git",
121
- :scm_url => "git://github.com./arangamani/jenkins_api_client.git",
122
- :scm_branch => "master"
123
- }
124
- test_and_validate(
125
- name,
126
- params,
127
- "<url>git://github.com./arangamani/jenkins_api_client.git</url>"
128
- )
129
- end
130
- it "Should create a freestyle job with SVN SCM provider" do
131
- name = "test_job_with_subversion_scm"
132
- params = {
133
- :name => name,
134
- :scm_provider => "subversion",
135
- :scm_url => "http://svn.freebsd.org/base/",
136
- :scm_branch => "master"
137
- }
138
- test_and_validate(
139
- name,
140
- params,
141
- "<remote>http://svn.freebsd.org/base/</remote>"
142
- )
143
- end
144
- it "Should create a freestyle job with CVS SCM provider with branch" do
145
- name = "test_job_with_cvs_scm_branch"
146
- params = {
147
- :name => name,
148
- :scm_provider => "cvs",
149
- :scm_url => "http://cvs.NetBSD.org",
150
- :scm_module => "src",
151
- :scm_branch => "MAIN"
152
- }
153
- test_and_validate(
154
- name,
155
- params,
156
- "<cvsroot>http://cvs.NetBSD.org</cvsroot>"
157
- )
158
- end
159
- it "Should create a freestyle job with CVS SCM provider with tag" do
160
- name = "test_job_with_cvs_scm_tag"
161
- params = {
162
- :name => name,
163
- :scm_provider => "cvs",
164
- :scm_url => "http://cvs.NetBSD.org",
165
- :scm_module => "src",
166
- :scm_tag => "MAIN"
167
- }
168
- test_and_validate(
169
- name,
170
- params,
171
- "<cvsroot>http://cvs.NetBSD.org</cvsroot>"
172
- )
173
- end
174
- it "Should raise an error if unsupported SCM is specified" do
175
- name = "test_job_unsupported_scm"
176
- params = {
177
- :name => name,
178
- :scm_provider => "non-existent",
179
- :scm_url => "http://non-existent.com/non-existent.non",
180
- :scm_branch => "master"
181
- }
182
- expect(
183
- lambda{ @client.job.create_freestyle(params) }
184
- ).to raise_error
185
- end
186
- it "Should create a freestyle job with restricted_node option" do
187
- name = "test_job_restricted_node"
188
- params = {
189
- :name => name,
190
- :restricted_node => "master"
191
- }
192
- test_and_validate(name, params)
193
- end
194
- it "Should create a freestyle job with" +
195
- " block_build_when_downstream_building option" do
196
- name = "test_job_block_build_when_downstream_building"
197
- params = {
198
- :name => name,
199
- :block_build_when_downstream_building => true,
200
- }
201
- test_and_validate(name, params)
202
- end
203
- it "Should create a freestyle job with" +
204
- " block_build_when_upstream_building option" do
205
- name = "test_job_block_build_when_upstream_building"
206
- params = {
207
- :name => name,
208
- :block_build_when_upstream_building => true
209
- }
210
- test_and_validate(name, params)
211
- end
212
- it "Should create a freestyle job with concurrent_build option" do
213
- name = "test_job_concurrent_build"
214
- params = {
215
- :name => name,
216
- :concurrent_build => true
217
- }
218
- test_and_validate(name, params)
219
- end
220
- it "Should create a freestyle job with timer option" do
221
- name = "test_job_using_timer"
222
- params = {
223
- :name => name,
224
- :timer => "* * * * *"
225
- }
226
- test_and_validate(name, params)
227
- end
228
- it "Should create a freestyle job with child projects option" do
229
- name = "test_job_child_projects"
230
- params = {
231
- :name => name,
232
- :child_projects => @job_name,
233
- :child_threshold => "success"
234
- }
235
- test_and_validate(name, params)
236
- end
237
- it "Should create a freestyle job with notification_email option" do
238
- name = "test_job_notification_email"
239
- params = {
240
- :name => name,
241
- :notification_email => "kannan@testdomain.com"
242
- }
243
- test_and_validate(name, params)
244
- end
245
- it "Should create a freestyle job with notification for" +
246
- " individual skype targets" do
247
- name = "test_job_with_individual_skype_targets"
248
- params = {
249
- :name => name,
250
- :skype_targets => "testuser"
251
- }
252
- test_and_validate(name, params)
253
- end
254
- it "Should create a freestyle job with notification for" +
255
- " group skype targets" do
256
- name = "test_job_with_group_skype_targets"
257
- params = {
258
- :name => name,
259
- :skype_targets => "*testgroup"
260
- }
261
- test_and_validate(name, params)
262
- end
263
- it "Should create a freestyle job with complex skype" +
264
- " configuration" do
265
- name = "test_job_with_complex_skype_configuration"
266
- params = {
267
- :name => name,
268
- :skype_targets => "testuser *testgroup anotheruser *anothergroup",
269
- :skype_strategy => "failure_and_fixed",
270
- :skype_notify_on_build_start => true,
271
- :skype_notify_suspects => true,
272
- :skype_notify_culprits => true,
273
- :skype_notify_fixers => true,
274
- :skype_notify_upstream_committers => false,
275
- :skype_message => "summary_and_scm_changes"
276
- }
277
- test_and_validate(name, params)
278
- end
279
- it "Should raise an error if the input parameters is not a Hash" do
280
- expect(
281
- lambda {
282
- @client.job.create_freestyle("a_string")
283
- }
284
- ).to raise_error(ArgumentError)
285
- end
286
- it "Should raise an error if the required name paremeter is missing" do
287
- expect(
288
- lambda {
289
- @client.job.create_freestyle(:shell_command => "sleep 60")
290
- }
291
- ).to raise_error(ArgumentError)
292
- end
293
- end
294
-
295
- describe "#copy" do
296
- it "accepts the from and to job name and copies the job" do
297
- xml = @helper.create_job_xml
298
- @client.job.create("from_job_copy_test", xml)
299
- @client.job.copy("from_job_copy_test", "to_job_copy_test")
300
- @client.job.list(".*_job_copy_test").should == [
301
- "from_job_copy_test", "to_job_copy_test"
302
- ]
303
- @client.job.delete("from_job_copy_test")
304
- @client.job.delete("to_job_copy_test")
305
- end
306
- it "accepts the from job name and copies the from job to the" +
307
- " copy_of_from job" do
308
- xml = @helper.create_job_xml
309
- @client.job.create("from_job_copy_test", xml)
310
- @client.job.copy("from_job_copy_test")
311
- @client.job.list(".*_job_copy_test").should == [
312
- "copy_of_from_job_copy_test", "from_job_copy_test"
313
- ]
314
- @client.job.delete("from_job_copy_test")
315
- @client.job.delete("copy_of_from_job_copy_test")
316
- end
317
- end
318
-
319
- describe "#add_email_notification" do
320
- it "Should accept email address and add to existing job" do
321
- name = "email_notification_test_job"
322
- params = {:name => name}
323
- @valid_post_responses.should include(
324
- @client.job.create_freestyle(params).to_i
325
- )
326
- @valid_post_responses.should include(
327
- @client.job.add_email_notification(
328
- :name => name,
329
- :notification_email => "testuser@testdomain.com"
330
- ).to_i
331
- )
332
- @valid_post_responses.should include(
333
- @client.job.delete(name).to_i
334
- )
335
- end
336
- end
337
-
338
- describe "#add_skype_notification" do
339
- it "Should accept skype configuration and add to existing job" do
340
- name = "skype_notification_test_job"
341
- params = {
342
- :name => name
343
- }
344
- @valid_post_responses.should include(
345
- @client.job.create_freestyle(params).to_i
346
- )
347
- @valid_post_responses.should include(
348
- @client.job.add_skype_notification(
349
- :name => name,
350
- :skype_targets => "testuser"
351
- ).to_i
352
- )
353
- @valid_post_responses.should include(
354
- @client.job.delete(name).to_i
355
- )
356
- end
357
- end
358
-
359
- describe "#rename" do
360
- it "Should accept new and old job names and rename the job" do
361
- xml = @helper.create_job_xml
362
- @client.job.create("old_job_rename_test", xml)
363
- @client.job.rename("old_job_rename_test", "new_job_rename_test")
364
- @client.job.list("old_job_rename_test").should == []
365
- resp = @client.job.list("new_job_rename_test")
366
- resp.size.should == 1
367
- resp.first.should == "new_job_rename_test"
368
- @client.job.delete("new_job_rename_test")
369
- end
370
- end
371
-
372
- describe "#recreate" do
373
- it "Should be able to re-create a job" do
374
- @valid_post_responses.should include(
375
- @client.job.recreate("qwerty_nonexistent_job").to_i
376
- )
377
- end
378
- end
379
-
380
- describe "#change_description" do
381
- it "Should be able to change the description of a job" do
382
- @valid_post_responses.should include(
383
- @client.job.change_description("qwerty_nonexistent_job",
384
- "The description has been changed by the spec test").to_i
385
- )
386
- end
387
- end
388
-
389
- describe "#delete" do
390
- it "Should be able to delete a job" do
391
- @valid_post_responses.should include(
392
- @client.job.delete("qwerty_nonexistent_job").to_i
393
- )
394
- end
395
- end
396
-
397
- describe "#wipe_out_workspace" do
398
- it "Should be able to wipe out the workspace of a job" do
399
- xml = @helper.create_job_xml
400
- @client.job.create("wipeout_job_test", xml)
401
- @valid_post_responses.should include(
402
- @client.job.wipe_out_workspace("wipeout_job_test").to_i
403
- )
404
- @client.job.delete("wipeout_job_test")
405
- end
406
- end
407
-
408
- describe "#list_all" do
409
- it "Should list all jobs" do
410
- @client.job.list_all.class.should == Array
411
- end
412
- end
413
-
414
- describe "#list" do
415
- it "Should return job names based on the filter" do
416
- names = @client.job.list(@filter)
417
- names.class.should == Array
418
- names.each { |name|
419
- name.should match /#{@filter}/i
420
- }
421
- end
422
- end
423
-
424
- describe "#list_by_status" do
425
- it "Should be able to list jobs by status" do
426
- names = @client.job.list_by_status('success')
427
- names.class.should == Array
428
- names.each do |name|
429
- status = @client.job.get_current_build_status(name)
430
- status.should == 'success'
431
- end
432
- end
433
- end
434
-
435
- describe "#list_all_with_details" do
436
- it "Should return all job names with details" do
437
- @client.job.list_all_with_details.class.should == Array
438
- end
439
- end
440
-
441
- describe "#list_details" do
442
- it "Should list details of a particular job" do
443
- job_name = @client.job.list(@filter)[0]
444
- job_name.class.should == String
445
- @client.job.list_details(job_name).class.should == Hash
446
- end
447
- end
448
-
449
- describe "#get_upstream_projects" do
450
- it "Should list upstream projects of the specified job" do
451
- @client.job.get_upstream_projects(@job_name).class.should == Array
452
- end
453
- end
454
-
455
- describe "#get_downstream_projects" do
456
- it "Should list downstream projects of the specified job" do
457
- @client.job.get_downstream_projects(@job_name).class.should == Array
458
- end
459
- end
460
-
461
- describe "#get_builds" do
462
- it "Should get builds of a specified job" do
463
- @client.job.get_builds(@job_name).class.should == Array
464
- end
465
- end
466
-
467
- describe "#get_current_build_status" do
468
- it "Should obtain the current build status for the specified job" do
469
- build_status = @client.job.get_current_build_status(@job_name)
470
- build_status.class.should == String
471
- valid_build_status = [
472
- "not_run",
473
- "aborted",
474
- "success",
475
- "failure",
476
- "unstable",
477
- "running"
478
- ]
479
- valid_build_status.include?(build_status).should be_true
480
- end
481
- end
482
-
483
- describe "#build" do
484
-
485
- def wait_for_job_to_finish(job_name)
486
- while @client.job.get_current_build_status(@job_name) == "running" do
487
- # Waiting for this job to finish so it doesn't affect other tests
488
- sleep 10
489
- end
490
- end
491
-
492
- it "Should build the specified job" do
493
- @client.job.get_current_build_status(
494
- @job_name
495
- ).should_not == "running"
496
- response = @client.job.build(@job_name)
497
- # As of Jenkins version 1.519 the job build responds with a 201
498
- # status code.
499
- @valid_post_responses.should include(response.to_i)
500
- # Sleep for 10 seconds so we don't hit the Jenkins quiet period (5
501
- # seconds)
502
- sleep 10
503
- @client.job.get_current_build_status(@job_name).should == "running"
504
- wait_for_job_to_finish(@job_name)
505
- end
506
-
507
- it "Should build the specified job (wait for start)" do
508
- @client.job.get_current_build_status(
509
- @job_name
510
- ).should_not == "running"
511
- expected_build_id = (@client.job.get_current_build_number(@job_name) || 0) + 1
512
-
513
- build_opts = {
514
- 'build_start_timeout' => 10,
515
- 'progress_proc' => lambda do |max_wait, curr_wait, poll_count|
516
- puts "Waited #{curr_wait}s of #{max_wait}s max - poll count = #{poll_count}"
517
- end,
518
- 'completion_proc' => lambda do |build_number, cancelled|
519
- if build_number
520
- puts "Wait over: build #{build_number} started"
521
- else
522
- puts "Wait over: build not started, build #{cancelled ? "" : "NOT "} cancelled"
523
- end
524
- end
525
- }
526
- build_id = @client.job.build(@job_name, {}, build_opts)
527
- build_id.should_not be_nil
528
- build_id.should eql(expected_build_id)
529
- @client.job.get_current_build_status(@job_name).should == "running"
530
- wait_for_job_to_finish(@job_name)
531
- end
532
-
533
- # This build doesn't start in time, but we don't cancel it, so it will run if
534
- # Jenkins gets to it
535
- it "Should build the specified job (wait for start - but not long enough)" do
536
- @client.job.get_current_build_status(
537
- @job_name
538
- ).should_not == "running"
539
-
540
- build_opts = {
541
- 'build_start_timeout' => 1,
542
- 'progress_proc' => lambda do |max_wait, curr_wait, poll_count|
543
- puts "Waited #{curr_wait}s of #{max_wait}s max - poll count = #{poll_count}"
544
- end,
545
- 'completion_proc' => lambda do |build_number, cancelled|
546
- if build_number
547
- puts "Wait over: build #{build_number} started"
548
- else
549
- puts "Wait over: build not started, build #{cancelled ? "" : "NOT "}cancelled"
550
- end
551
- end
552
- }
553
- expect( lambda { @client.job.build(@job_name, {}, build_opts) } ).to raise_error(Timeout::Error)
554
- # Sleep for 10 seconds so we don't hit the Jenkins quiet period (5
555
- # seconds)
556
- sleep 10
557
- @client.job.get_current_build_status(@job_name).should == "running"
558
- wait_for_job_to_finish(@job_name)
559
- end
560
-
561
- # This build doesn't start in time, and we will attempt to cancel it so it
562
- # doesn't run
563
- it "Should build the specified job (wait for start - but not long enough, cancelled)" do
564
- @client.job.get_current_build_status(
565
- @job_name
566
- ).should_not == "running"
567
-
568
- build_opts = {
569
- 'build_start_timeout' => 1,
570
- 'cancel_on_build_start_timeout' => true,
571
- 'progress_proc' => lambda do |max_wait, curr_wait, poll_count|
572
- puts "Waited #{curr_wait}s of #{max_wait}s max - poll count = #{poll_count}"
573
- end,
574
- 'completion_proc' => lambda do |build_number, cancelled|
575
- if build_number
576
- puts "Wait over: build #{build_number} started"
577
- else
578
- puts "Wait over: build not started, build #{cancelled ? "" : "NOT "}cancelled"
579
- end
580
- end
581
- }
582
- expect( lambda { @client.job.build(@job_name, {}, build_opts) } ).to raise_error(Timeout::Error)
583
- end
584
- end
585
-
586
- describe "#poll" do
587
- it "Should poll the specified job for scm changes" do
588
- response = @client.job.poll(@job_name)
589
- @valid_post_responses.should include(response.to_i)
590
- end
591
- end
592
-
593
- describe "#disable" do
594
- it "Should disable the specified job and then enable it again" do
595
- @client.job.list_details(@job_name)['buildable'].should == true
596
- response = @client.job.disable(@job_name)
597
- response.to_i.should == 302
598
- sleep 3
599
- @client.job.list_details(@job_name)['buildable'].should == false
600
- response = @client.job.enable(@job_name)
601
- response.to_i.should == 302
602
- sleep 3
603
- @client.job.list_details(@job_name)['buildable'].should == true
604
- end
605
- end
606
-
607
- describe "#stop" do
608
- it "Should be able to abort a recent build of a running job" do
609
- @client.job.get_current_build_status(
610
- @job_name
611
- ).should_not == "running"
612
- @client.job.build(@job_name)
613
- sleep 10
614
- @client.job.get_current_build_status(@job_name).should == "running"
615
- sleep 5
616
- @valid_post_responses.should include(
617
- @client.job.stop_build(@job_name).to_i
618
- )
619
- sleep 5
620
- @client.job.get_current_build_status(@job_name).should == "aborted"
621
- end
622
- end
623
-
624
- describe "#restrict_to_node" do
625
- it "Should be able to restrict a job to a node" do
626
- @valid_post_responses.should include(
627
- @client.job.restrict_to_node(@job_name, 'master').to_i
628
- )
629
- # Run it again to make sure that the replace existing node works
630
- @valid_post_responses.should include(
631
- @client.job.restrict_to_node(@job_name, 'master').to_i
632
- )
633
- end
634
- end
635
-
636
- describe "#chain" do
637
- it "Should be able to chain all jobs" do
638
- # Filter jobs to be chained
639
- jobs = @client.job.list(@filter)
640
- jobs.class.should == Array
641
- start_jobs = @client.job.chain(jobs, 'success', ["all"])
642
- start_jobs.class.should == Array
643
- start_jobs.length.should == 1
644
- end
645
- it "Should be able to chain jobs based on the specified criteria" do
646
- jobs = @client.job.list(@filter)
647
- jobs.class.should == Array
648
- start_jobs = @client.job.chain(
649
- jobs,
650
- 'failure',
651
- ["not_run", "aborted", 'failure'],
652
- 3
653
- )
654
- start_jobs.class.should == Array
655
- start_jobs.length.should == 3
656
- end
657
- end
658
-
659
- end
660
-
661
- after(:all) do
662
- job_names = @client.job.list(@filter)
663
- job_names.each { |job_name|
664
- @client.job.delete(job_name)
665
- }
666
- end
667
-
668
- end
669
- end