-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy resource "jenkins_cli" from heavywater/chef-jenkins.
- Loading branch information
Showing
7 changed files
with
245 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Description | ||
=========== | ||
Installs and configures Jenkins CI server. | ||
|
||
Attributes | ||
========== | ||
|
||
* jenkins[:java_home] - Java install path, used for for cli commands | ||
* jenkins[:server][:home] - JENKINS_HOME directory | ||
* jenkins[:server][:user] - User the Jenkins server runs as | ||
* jenkins[:server][:group] - Jenkins user primary group | ||
* jenkins[:server][:port] - TCP listen port for the Jenkins server | ||
* jenkins[:server][:url] - Base URL of the Jenkins server | ||
* jenkins[:node][:home] - Home directory of the node | ||
|
||
Usage | ||
===== | ||
|
||
'default' recipe | ||
---------------- | ||
|
||
Installs a Jenkins CI server. | ||
|
||
'jenkins_cli' resource provider | ||
------------------------------- | ||
|
||
This resource can be used to execute the Jenkins cli from your recipes. For example, install git plugin and restart Jenkins: | ||
|
||
jenkins_cli "install-plugin git" | ||
jenkins_cli "safe-restart" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
default[:jenkins][:java_home] = ENV['JAVA_HOME'] | ||
|
||
default[:jenkins][:server][:home] = "/var/lib/jenkins" | ||
default[:jenkins][:server][:user] = "jenkins" | ||
|
||
case node[:platform] | ||
when "debian", "ubuntu" | ||
default[:jenkins][:server][:group] = "nogroup" | ||
else | ||
default[:jenkins][:server][:group] = node[:jenkins][:server][:user] | ||
end | ||
|
||
default[:jenkins][:server][:port] = 8080 | ||
default[:jenkins][:server][:host] = "127.0.0.1" | ||
default[:jenkins][:server][:url] = "http://#{node[:jenkins][:server][:host]}:#{node[:jenkins][:server][:port]}" | ||
|
||
#download the latest version of plugins, bypassing update center | ||
#example: ["git", "URLSCM", ...] | ||
default[:jenkins][:server][:plugins] = [] | ||
|
||
#See Jenkins >> Nodes >> $name >> Configure | ||
|
||
#"Remote FS root" | ||
default[:jenkins][:node][:home] = "/home/jenkins" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,11 @@ | |
maintainer "OKINAKA Kenshin" | ||
maintainer_email "[email protected]" | ||
license "Apache 2.0" | ||
description "Installs and configures Jenkins CI server & slaves" | ||
description "Installs and configures Jenkins CI server" | ||
version "0.0.1" | ||
|
||
depends "java" | ||
recommends "apt" | ||
recommends "yum" | ||
|
||
%w{ debian ubuntu centos redhat fedora scientific amazon }.each do |os| | ||
supports os | ||
end | ||
|
||
recipe "jenkins", "Installs jenkins" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Based on hudson | ||
# Provider:: cli | ||
# | ||
# Author:: Doug MacEachern <[email protected]> | ||
# Author:: Fletcher Nichol <[email protected]> | ||
# | ||
# Copyright:: 2010, VMware, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
def action_run | ||
url = @new_resource.url || node[:jenkins][:server][:url] | ||
home = @new_resource.home || node[:jenkins][:node][:home] | ||
|
||
#recipes will chown to jenkins later if this doesn't already exist | ||
directory "home for jenkins-cli.jar" do | ||
action :create | ||
path node[:jenkins][:node][:home] | ||
end | ||
|
||
cli_jar = ::File.join(home, "jenkins-cli.jar") | ||
remote_file cli_jar do | ||
source "#{url}/jnlpJars/jenkins-cli.jar" | ||
not_if { ::File.exists?(cli_jar) } | ||
end | ||
|
||
java_home = node[:jenkins][:java_home] || (node.has_key?(:java) ? node[:java][:jdk_dir] : nil) | ||
if java_home == nil | ||
java = "java" | ||
else | ||
java = ::File.join(java_home, "bin", "java") | ||
end | ||
|
||
command = "#{java} -jar #{cli_jar} -s #{url} #{@new_resource.command}" | ||
|
||
jenkins_execute command do | ||
cwd home | ||
block { |stdout| new_resource.block.call(stdout) } if new_resource.block | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Based on hudson | ||
# Provider:: execute | ||
# | ||
# Author:: Doug MacEachern <[email protected]> | ||
# Author:: Fletcher Nichol <[email protected]> | ||
# | ||
# Copyright:: 2010, VMware, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
#pruned Chef::Provider::Execute + optional `block' param | ||
|
||
include Chef::Mixin::Command | ||
|
||
def action_run | ||
args = { | ||
:command => @new_resource.command, | ||
:command_string => @new_resource.to_s, | ||
} | ||
args[:only_if] = @new_resource.only_if if @new_resource.only_if | ||
args[:not_if] = @new_resource.not_if if @new_resource.not_if | ||
args[:timeout] = @new_resource.timeout if @new_resource.timeout | ||
args[:cwd] = @new_resource.cwd if @new_resource.cwd | ||
|
||
status, stdout, stderr = output_of_command(args[:command], args) | ||
if status.exitstatus == 0 | ||
@new_resource.block.call(stdout) if @new_resource.block | ||
@new_resource.updated_by_last_action(true) | ||
Chef::Log.info("Ran #{@new_resource} successfully") | ||
else | ||
command_output = "JENKINS STDOUT: #{stdout}" | ||
command_output << "JENKINS STDERR: #{stderr}" | ||
handle_command_failures(status, command_output, args) | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Based on hudson | ||
# Resource:: cli | ||
# | ||
# Author:: Doug MacEachern <[email protected]> | ||
# Author:: Fletcher Nichol <[email protected]> | ||
# | ||
# Copyright:: 2010, VMware, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
actions :run | ||
|
||
attribute :url, :kind_of => String | ||
attribute :home, :kind_of => String | ||
attribute :command, :kind_of => String | ||
attribute :timeout, :kind_of => Integer | ||
attribute :block, :kind_of => Proc | ||
|
||
def initialize(name, run_context=nil) | ||
super | ||
@action = :run | ||
@command = name | ||
end | ||
|
||
def block(&block) | ||
if block_given? and block | ||
@block = block | ||
else | ||
@block | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# Cookbook Name:: jenkins | ||
# Based on hudson | ||
# Resource:: execute | ||
# | ||
# Author:: Doug MacEachern <[email protected]> | ||
# Author:: Fletcher Nichol <[email protected]> | ||
# | ||
# Copyright:: 2010, VMware, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
actions :run | ||
|
||
attribute :command, :kind_of => String | ||
attribute :cwd, :kind_of => String | ||
attribute :timeout, :kind_of => Integer | ||
attribute :block, :kind_of => Proc | ||
|
||
def initialize(name, run_context=nil) | ||
super | ||
@action = :run | ||
@command = name | ||
end | ||
|
||
def block(&block) | ||
if block_given? and block | ||
@block = block | ||
else | ||
@block | ||
end | ||
end |