jenkins_api_client 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +9 -0
- data/jenkins_api_client.gemspec +5 -3
- data/lib/jenkins_api_client.rb +1 -0
- data/lib/jenkins_api_client/client.rb +7 -4
- data/lib/jenkins_api_client/job.rb +44 -4
- data/lib/jenkins_api_client/plugin_manager.rb +1 -1
- data/lib/jenkins_api_client/plugin_settings/hipchat.rb +1 -1
- data/lib/jenkins_api_client/plugin_settings/workspace_cleanup.rb +35 -0
- data/lib/jenkins_api_client/version.rb +1 -1
- data/spec/unit_tests/job_spec.rb +74 -0
- data/spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb +31 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae6ba9e0eccf49a825c6adc02e7d6d3a6200ac9d
|
4
|
+
data.tar.gz: eeb2d4cfb1d2858e157c74aa6b146ba572bf7246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e6088e2b7231336b556fca98788f58be9abb0d68a739ecc73789adf22f23532519cd7f08b7b4e7ed9d5f5a96db24de9ef3f303752e14784aae91e9a129d9acc
|
7
|
+
data.tar.gz: 148deba58cb95bb445af9b232613c740648590def0e96cfdb4bc5c7cb6687a68e17682cf8c3f9408e5ae086ecec5bb69240017547c0872a71a5376e071b77aa8
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ CHANGELOG
|
|
4
4
|
upcoming
|
5
5
|
--------
|
6
6
|
|
7
|
+
v1.2.0 [12-NOV-2014]
|
8
|
+
----------------------
|
9
|
+
* [#156][] Added workspace cleanup plugin. Credit [@hubert][]
|
10
|
+
* [#157][] Added ability to configure SCM trigger via job creation. Credit: [@hubert][]
|
11
|
+
* [#158][] Add ability to configure post build artifact archiver step. Credit: [@hubert][]
|
12
|
+
|
7
13
|
v1.1.0 [05-NOV-2014]
|
8
14
|
----------------------
|
9
15
|
* [#145][] Fix `BuildQueue#get_details` to compare against task_name. Credit: [@notruthless][]
|
@@ -285,6 +291,9 @@ v0.0.1 [15-OCT-2012]
|
|
285
291
|
[#149]: https://github.com/arangamani/jenkins_api_client/issues/149
|
286
292
|
[#151]: https://github.com/arangamani/jenkins_api_client/issues/151
|
287
293
|
[#153]: https://github.com/arangamani/jenkins_api_client/issues/153
|
294
|
+
[#156]: https://github.com/arangamani/jenkins_api_client/issues/156
|
295
|
+
[#157]: https://github.com/arangamani/jenkins_api_client/issues/157
|
296
|
+
[#158]: https://github.com/arangamani/jenkins_api_client/issues/158
|
288
297
|
[@Loa]: https://github.com/Loa
|
289
298
|
[@Niarfe]: https://github.com/Niarfe
|
290
299
|
[@bobbrez]: https://github.com/bobbrez
|
data/jenkins_api_client.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: jenkins_api_client 1.
|
5
|
+
# stub: jenkins_api_client 1.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "jenkins_api_client"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kannan Manickam"]
|
14
|
-
s.date = "2014-11-
|
14
|
+
s.date = "2014-11-13"
|
15
15
|
s.description = "\nThis is a simple and easy-to-use Jenkins Api client with features focused on\nautomating Job configuration programaticaly and so forth"
|
16
16
|
s.email = ["arangamani.kannan@gmail.com"]
|
17
17
|
s.executables = ["jenkinscli"]
|
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
"lib/jenkins_api_client/plugin_settings/base.rb",
|
47
47
|
"lib/jenkins_api_client/plugin_settings/collection.rb",
|
48
48
|
"lib/jenkins_api_client/plugin_settings/hipchat.rb",
|
49
|
+
"lib/jenkins_api_client/plugin_settings/workspace_cleanup.rb",
|
49
50
|
"lib/jenkins_api_client/system.rb",
|
50
51
|
"lib/jenkins_api_client/urihelper.rb",
|
51
52
|
"lib/jenkins_api_client/user.rb",
|
@@ -73,6 +74,7 @@ Gem::Specification.new do |s|
|
|
73
74
|
"spec/unit_tests/node_spec.rb",
|
74
75
|
"spec/unit_tests/plugin_settings/colllection_spec.rb",
|
75
76
|
"spec/unit_tests/plugin_settings/hipchat_spec.rb",
|
77
|
+
"spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb",
|
76
78
|
"spec/unit_tests/plugin_spec.rb",
|
77
79
|
"spec/unit_tests/spec_helper.rb",
|
78
80
|
"spec/unit_tests/system_spec.rb",
|
data/lib/jenkins_api_client.rb
CHANGED
@@ -44,6 +44,7 @@ module JenkinsApi
|
|
44
44
|
|
45
45
|
autoload :Base, 'jenkins_api_client/plugin_settings/base'
|
46
46
|
autoload :Hipchat, 'jenkins_api_client/plugin_settings/hipchat'
|
47
|
+
autoload :WorkspaceCleanup, 'jenkins_api_client/plugin_settings/workspace_cleanup'
|
47
48
|
autoload :Collection, 'jenkins_api_client/plugin_settings/collection'
|
48
49
|
end
|
49
50
|
end
|
@@ -74,7 +74,8 @@ module JenkinsApi
|
|
74
74
|
#
|
75
75
|
# @option args [String] :server_ip the IP address of the Jenkins CI server
|
76
76
|
# @option args [String] :server_port the port on which the Jenkins listens
|
77
|
-
# @option args [String] :server_url the full URL address of the Jenkins CI server (http/https). This can include
|
77
|
+
# @option args [String] :server_url the full URL address of the Jenkins CI server (http/https). This can include
|
78
|
+
# username/password. :username/:password options will override any user/pass value in the URL
|
78
79
|
# @option args [String] :username the username used for connecting to the server (optional)
|
79
80
|
# @option args [String] :password the password or API Key for connecting to the CI server (optional)
|
80
81
|
# @option args [String] :password_base64 the password with base64 encoded format for connecting to the CI
|
@@ -263,9 +264,11 @@ module JenkinsApi
|
|
263
264
|
request = Net::HTTP::Get.new(uri.request_uri)
|
264
265
|
request.basic_auth(@username, @password)
|
265
266
|
response = http.request(request)
|
266
|
-
|
267
|
-
|
268
|
-
|
267
|
+
if response.code == "200"
|
268
|
+
File.write(File.expand_path(filename), response.body)
|
269
|
+
else
|
270
|
+
raise "Couldn't get the artifact"
|
271
|
+
end
|
269
272
|
end
|
270
273
|
|
271
274
|
# Connects to the Jenkins server, sends the specified request and returns
|
@@ -322,14 +322,19 @@ module JenkinsApi
|
|
322
322
|
"#{params[:block_build_when_downstream_building]}")
|
323
323
|
xml.blockBuildWhenUpstreamBuilding(
|
324
324
|
"#{params[:block_build_when_upstream_building]}")
|
325
|
-
|
326
|
-
|
325
|
+
xml.triggers.vector do
|
326
|
+
if params[:timer]
|
327
327
|
xml.send("hudson.triggers.TimerTrigger") do
|
328
328
|
xml.spec params[:timer]
|
329
329
|
end
|
330
330
|
end
|
331
|
-
|
332
|
-
|
331
|
+
|
332
|
+
if params[:scm_trigger]
|
333
|
+
xml.send("hudson.triggers.SCMTrigger") do
|
334
|
+
xml.spec params[:scm_trigger]
|
335
|
+
xml.ignorePostCommitHooks params.fetch(:ignore_post_commit_hooks) { false }
|
336
|
+
end
|
337
|
+
end
|
333
338
|
end
|
334
339
|
xml.concurrentBuild "#{params[:concurrent_build]}"
|
335
340
|
# Shell command stuff
|
@@ -348,6 +353,7 @@ module JenkinsApi
|
|
348
353
|
notification_email(params, xml) if params[:notification_email]
|
349
354
|
# Build portion of XML that adds skype notification
|
350
355
|
skype_notification(params, xml) if params[:skype_targets]
|
356
|
+
artifact_archiver(params[:artifact_archiver], xml)
|
351
357
|
end
|
352
358
|
xml.buildWrappers
|
353
359
|
end
|
@@ -424,6 +430,40 @@ module JenkinsApi
|
|
424
430
|
end
|
425
431
|
end
|
426
432
|
|
433
|
+
# Configure post-build step to archive artifacts
|
434
|
+
#
|
435
|
+
# @param artifact_params [Hash] parameters controlling how artifacts are archived
|
436
|
+
#
|
437
|
+
# @option artifact_params [String] :artifact_files
|
438
|
+
# pattern or names of files to archive
|
439
|
+
# @option artifact_params [String] :excludes
|
440
|
+
# pattern or names of files to exclude
|
441
|
+
# @option artifact_params [Boolean] :fingerprint (false)
|
442
|
+
# fingerprint the archives
|
443
|
+
# @option artifact_params [Boolean] :allow_empty_archive (false)
|
444
|
+
# whether to allow empty archives
|
445
|
+
# @option artifact_params [Boolean] :only_if_successful (false)
|
446
|
+
# only archive if successful
|
447
|
+
# @option artifact_params [Boolean] :default_excludes (false)
|
448
|
+
# exclude defaults automatically
|
449
|
+
#
|
450
|
+
# @return [Nokogiri::XML::Builder]
|
451
|
+
#
|
452
|
+
def artifact_archiver(artifact_params, xml)
|
453
|
+
return xml if artifact_params.nil?
|
454
|
+
|
455
|
+
xml.send('hudson.tasks.ArtifactArchiver') do |x|
|
456
|
+
x.artifacts artifact_params.fetch(:artifact_files) { '' }
|
457
|
+
x.excludes artifact_params.fetch(:excludes) { '' }
|
458
|
+
x.fingerprint artifact_params.fetch(:fingerprint) { false }
|
459
|
+
x.allowEmptyArchive artifact_params.fetch(:allow_empty_archive) { false }
|
460
|
+
x.onlyIfSuccessful artifact_params.fetch(:only_if_successful) { false }
|
461
|
+
x.defaultExcludes artifact_params.fetch(:default_excludes) { false }
|
462
|
+
end
|
463
|
+
|
464
|
+
xml
|
465
|
+
end
|
466
|
+
|
427
467
|
# Rename a job given the old name and new name
|
428
468
|
#
|
429
469
|
# @param [String] old_job Name of the old job
|
@@ -26,7 +26,7 @@ module JenkinsApi
|
|
26
26
|
# installed plugins, installing new plgins through hacks, and performing a
|
27
27
|
# lot of operations on installed plugins. It also gives the ability to
|
28
28
|
# obtain the details about available plugins in Jenkins update center by
|
29
|
-
#
|
29
|
+
# communicating with /updateCenter API.
|
30
30
|
#
|
31
31
|
class PluginManager
|
32
32
|
|
@@ -28,7 +28,7 @@ module JenkinsApi
|
|
28
28
|
# This gives some flexibility for creating/updating simple jobs so the
|
29
29
|
# user doesn't have to learn about handling xml.
|
30
30
|
#
|
31
|
-
# @param
|
31
|
+
# @param xml_doc [Nokogiri::XML::Document] xml document to be updated with the plugin configuration
|
32
32
|
#
|
33
33
|
# @return [Nokogiri::XML::Document]
|
34
34
|
def configure(xml_doc)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module JenkinsApi
|
2
|
+
class Client
|
3
|
+
module PluginSettings
|
4
|
+
class WorkspaceCleanup < Base
|
5
|
+
|
6
|
+
# @option params [Boolean] :delete_dirs (false)
|
7
|
+
# whether to also apply pattern on directories
|
8
|
+
# @option params [String] :cleanup_parameters
|
9
|
+
# @option params [String] :external_delete
|
10
|
+
def initialize(params={})
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
# Create or Update a job with params given as a hash instead of the xml
|
15
|
+
# This gives some flexibility for creating/updating simple jobs so the
|
16
|
+
# user doesn't have to learn about handling xml.
|
17
|
+
#
|
18
|
+
# @param xml_doc [Nokogiri::XML::Document] xml document to be updated with the plugin configuration
|
19
|
+
#
|
20
|
+
# @return [Nokogiri::XML::Document]
|
21
|
+
def configure(xml_doc)
|
22
|
+
xml_doc.tap do |doc|
|
23
|
+
Nokogiri::XML::Builder.with(doc.at('buildWrappers')) do |build_wrappers|
|
24
|
+
build_wrappers.send('hudson.plugins.ws__cleanup.PreBuildCleanup') do |x|
|
25
|
+
x.deleteDirs @params.fetch(:delete_dirs) { false }
|
26
|
+
x.cleanupParameter @params.fetch(:cleanup_parameter) { '' }
|
27
|
+
x.externalDelete @params.fetch(:external_delete) { '' }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/unit_tests/job_spec.rb
CHANGED
@@ -641,6 +641,80 @@ describe JenkinsApi::Client::Job do
|
|
641
641
|
expect(@job.plugin_collection).to receive(:configure).and_return(Nokogiri::XML::Document.new(''))
|
642
642
|
@job.build_freestyle_config(name: 'foobar')
|
643
643
|
end
|
644
|
+
|
645
|
+
context 'scm_trigger and ignore_post_commit_hooks params' do
|
646
|
+
it 'configures triggers with a hudson.triggers.SCMTrigger' do
|
647
|
+
xml = @job.build_freestyle_config(
|
648
|
+
name: 'foobar',
|
649
|
+
scm_trigger: 'H 0 29 2 0',
|
650
|
+
ignore_post_commit_hooks: true
|
651
|
+
)
|
652
|
+
|
653
|
+
xml_config = Nokogiri::XML(xml)
|
654
|
+
expect(xml_config.at_css('triggers spec').content).to eql('H 0 29 2 0')
|
655
|
+
expect(xml_config.at_css('triggers ignorePostCommitHooks').content).to eql('true')
|
656
|
+
end
|
657
|
+
|
658
|
+
it 'does not add a tag to triggers if not passed scm_trigger param' do
|
659
|
+
xml = @job.build_freestyle_config(
|
660
|
+
name: 'foobar'
|
661
|
+
)
|
662
|
+
|
663
|
+
xml_config = Nokogiri::XML(xml)
|
664
|
+
expect(xml_config.at_css('triggers').children).to be_empty
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
context 'artifact archiver build step' do
|
669
|
+
context 'given artifact_archiver params' do
|
670
|
+
it 'configures with given params' do
|
671
|
+
artifact_archiver_params = {
|
672
|
+
artifact_files: '**',
|
673
|
+
excludes: 'foo',
|
674
|
+
fingerprint: true,
|
675
|
+
allow_empty_archive: true,
|
676
|
+
only_if_successful: true,
|
677
|
+
default_excludes: true,
|
678
|
+
}
|
679
|
+
xml = @job.build_freestyle_config(
|
680
|
+
name: 'foobar',
|
681
|
+
artifact_archiver: artifact_archiver_params,
|
682
|
+
)
|
683
|
+
xml_config = Nokogiri::XML(xml)
|
684
|
+
|
685
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/artifacts').content).to eql('**')
|
686
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/excludes').content).to eql('foo')
|
687
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/fingerprint').content).to eql('true')
|
688
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/allowEmptyArchive').content).to eql('true')
|
689
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/onlyIfSuccessful').content).to eql('true')
|
690
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/defaultExcludes').content).to eql('true')
|
691
|
+
end
|
692
|
+
|
693
|
+
it 'configures with defaults for non-specified options' do
|
694
|
+
xml = @job.build_freestyle_config(
|
695
|
+
name: 'foobar',
|
696
|
+
artifact_archiver: {},
|
697
|
+
)
|
698
|
+
xml_config = Nokogiri::XML(xml)
|
699
|
+
|
700
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/artifacts').content).to eql('')
|
701
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/excludes').content).to eql('')
|
702
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/fingerprint').content).to eql('false')
|
703
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/allowEmptyArchive').content).to eql('false')
|
704
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/onlyIfSuccessful').content).to eql('false')
|
705
|
+
expect(xml_config.at_xpath('//publishers/hudson.tasks.ArtifactArchiver/defaultExcludes').content).to eql('false')
|
706
|
+
end
|
707
|
+
end
|
708
|
+
|
709
|
+
context 'not given artifact_archiver params' do
|
710
|
+
it 'omits hudson.tasks.ArtifactArchiver tag' do
|
711
|
+
xml = @job.build_freestyle_config(name: 'foobar')
|
712
|
+
xml_config = Nokogiri::XML(xml)
|
713
|
+
|
714
|
+
expect(xml_config.xpath('//publishers/hudson.tasks.ArtifactArchiver')).to be_empty
|
715
|
+
end
|
716
|
+
end
|
717
|
+
end
|
644
718
|
end
|
645
719
|
|
646
720
|
context 'plugin settings' do
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe JenkinsApi::Client::PluginSettings::WorkspaceCleanup do
|
4
|
+
describe '#configure' do
|
5
|
+
context 'given a Nokogiri::XML::Builder object' do
|
6
|
+
let(:xml_doc) { Nokogiri::XML("<?xml version=\"1.0\"?>\n<buildWrappers>\n</buildWrappers>\n") }
|
7
|
+
|
8
|
+
it 'adds workspace cleanup configuration to the buildWrappers' do
|
9
|
+
workspace_cleanup_settings = JenkinsApi::Client::PluginSettings::WorkspaceCleanup.new
|
10
|
+
workspace_cleanup_settings.configure(xml_doc)
|
11
|
+
|
12
|
+
expect(xml_doc.at_css('buildWrappers deleteDirs').content).to eql('false')
|
13
|
+
expect(xml_doc.at_css('buildWrappers cleanupParameter').content).to eql('')
|
14
|
+
expect(xml_doc.at_css('buildWrappers externalDelete').content).to eql('')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'uses params if given' do
|
18
|
+
workspace_cleanup_settings = JenkinsApi::Client::PluginSettings::WorkspaceCleanup.new({
|
19
|
+
:delete_dirs => true,
|
20
|
+
:cleanup_parameter => 'foo',
|
21
|
+
:external_delete => 'bar',
|
22
|
+
})
|
23
|
+
workspace_cleanup_settings.configure(xml_doc)
|
24
|
+
|
25
|
+
expect(xml_doc.at_css('buildWrappers deleteDirs').content).to eql('true')
|
26
|
+
expect(xml_doc.at_css('buildWrappers cleanupParameter').content).to eql('foo')
|
27
|
+
expect(xml_doc.at_css('buildWrappers externalDelete').content).to eql('bar')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kannan Manickam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/jenkins_api_client/plugin_settings/base.rb
|
220
220
|
- lib/jenkins_api_client/plugin_settings/collection.rb
|
221
221
|
- lib/jenkins_api_client/plugin_settings/hipchat.rb
|
222
|
+
- lib/jenkins_api_client/plugin_settings/workspace_cleanup.rb
|
222
223
|
- lib/jenkins_api_client/system.rb
|
223
224
|
- lib/jenkins_api_client/urihelper.rb
|
224
225
|
- lib/jenkins_api_client/user.rb
|
@@ -246,6 +247,7 @@ files:
|
|
246
247
|
- spec/unit_tests/node_spec.rb
|
247
248
|
- spec/unit_tests/plugin_settings/colllection_spec.rb
|
248
249
|
- spec/unit_tests/plugin_settings/hipchat_spec.rb
|
250
|
+
- spec/unit_tests/plugin_settings/workspace_cleanup_spec.rb
|
249
251
|
- spec/unit_tests/plugin_spec.rb
|
250
252
|
- spec/unit_tests/spec_helper.rb
|
251
253
|
- spec/unit_tests/system_spec.rb
|