Permalink
Browse files

Initial clone copy from opscode/hudson cookbook.

  • Loading branch information...
0 parents commit c7e1785a2e99108e258e916c18ab73ddff3b153e @fnichol committed Feb 6, 2011
@@ -0,0 +1,168 @@
+= DESCRIPTION:
+
+Installs and configures Jenkins CI server & node slaves. Resource providers to support automation via jenkins-cli, including job create/update.
+
+= REQUIREMENTS:
+
+== Chef:
+
+* Chef version 0.9.10 or higher
+
+== Platform:
+
+* 'default' - Server installation - currently supports Red Hat/CentOS 5.x and Ubuntu 9.x/10.4
+
+* 'node_ssh' - Any platform that is running sshd.
+
+* 'node_jnlp' - Unix platforms. (depends on runit recipe)
+
+* 'node_windows' - Windows platforms only. Depends on .NET Framework, which can be installed with the windows::dotnetfx recipe.
+
+== Java:
+
+Jenkins requires Java 1.5 or higher, which can be installed via the Opscode java cookbook or windows::java recipe.
+
+== Jenkins node authentication:
+
+If your Jenkins instance requires authentication, you'll either need to embed user:pass in the jenkins.server.url or issue a jenkins-cli.jar login command prior to using the jenkins::node_* recipes. For example, define a role like so:
+
+ name "jenkins_ssh_node"
+ description "cli login & register ssh slave with Jenkins"
+ run_list %w(vmw::jenkins_login jenkins::node_ssh)
+
+Where the jenkins_login recipe is simply:
+
+ jenkins_cli "login --username #{node[:jenkins][:username]} --password #{node[:jenkins][:password]}"
+
+= ATTRIBUTES:
+
+* jenkins[:mirror] - Base URL for downloading Jenkins (server)
+* 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[:server][:plugins] - Download the latest version of plugins in this list, bypassing update center
+* jenkins[:node][:name] - Name of the node within Jenkins
+* jenkins[:node][:description] - Jenkins node description
+* jenkins[:node][:executors] - Number of node executors
+* jenkins[:node][:home] - Home directory ("Remote FS root") of the node
+* jenkins[:node][:labels] - Node labels
+* jenkins[:node][:mode] - Node usage mode, "normal" or "exclusive" (tied jobs only)
+* jenkins[:node][:launcher] - Node launch method, "jnlp", "ssh" or "command"
+* jenkins[:node][:availability] - "always" keeps node on-line, "demand" off-lines when idle
+* jenkins[:node][:in_demand_delay] - number of minutes for which jobs must be waiting in the queue before attempting to launch this slave.
+* jenkins[:node][:idle_delay] - number of minutes that this slave must remain idle before taking it off-line.
+* jenkins[:node][:env] - "Node Properties" -> "Environment Variables"
+* jenkins[:node][:user] - user the slave runs as
+* jenkins[:node][:ssh_host] - Hostname or IP Jenkins should connect to when launching an SSH slave
+* jenkins[:node][:ssh_port] - SSH slave port
+* jenkins[:node][:ssh_user] - SSH slave user name (only required if jenkins server and slave user is different)
+* jenkins[:node][:ssh_pass] - SSH slave password (not required when server is installed via default recipe)
+* jenkins[:node][:ssh_private_key] - jenkins master defaults to: `~/.ssh/id_rsa` (created by the default recipe)
+* jenkins[:node][:jvm_options] - SSH slave JVM options
+
+= USAGE:
+
+== 'default' recipe
+
+Installs a Jenkins CI server using the http://jenkins-ci.org/redhat RPM. The recipe also generates an ssh private key and stores the ssh public key in the node 'jenkins[:pubkey]' attribute for use by the node recipes.
+
+== 'node_ssh' recipe
+
+Creates the user and group for the Jenkins slave to run as and sets `.ssh/authorized_keys` to the 'jenkins[:pubkey]' attribute. The 'jenkins-cli.jar'[1] is downloaded from the Jenkins server and used to manage the nodes via the 'groovy'[2] cli command. Jenkins is configured to launch a slave agent on the node using its SSH slave plugin[3].
+
+[1] http://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
+[2] http://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
+[3] http://wiki.jenkins-ci.org/display/JENKINS/SSH+Slaves+plugin
+
+== 'node_jnlp' recipe
+
+Creates the user and group for the Jenkins slave to run as and '/jnlpJars/slave.jar' is downloaded from the Jenkins server. Depends on runit_service from the runit cookbook.
+
+== 'node_windows' recipe
+
+Creates the home directory for the node slave and sets 'JENKINS_HOME' and 'JENKINS_URL' system environment variables. The 'winsw'[1] Windows service wrapper will be downloaded and installed, along with generating `jenkins-slave.xml` from a template. Jenkins is configured with the node as a 'jnlp'[2] slave and '/jnlpJars/slave.jar' is downloaded from the Jenkins server. The 'jenkinsslave' service will be started the first time the recipe is run or if the service is not running. The 'jenkinsslave' service will be restarted if '/jnlpJars/slave.jar' has changed. The end results is functionally the same had you chosen the option to "Let Jenkins control this slave as a Windows service"[3].
+
+[1] http://weblogs.java.net/blog/2008/09/29/winsw-windows-service-wrapper-less-restrictive-license
+[2] http://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
+[3] http://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service
+
+== 'jenkins_cli' resource provider
+
+This resource can be used to execute the Jenkins cli from your recipes. For example, install plugins via update center and restart Jenkins:
+
+ %w(git URLSCM build-publisher).each do |plugin|
+ jenkins_cli "install-plugin #{plugin}"
+ jenkins_cli "safe-restart"
+ end
+
+== 'jenkins_node' resource provider
+
+This resource can be used to configure nodes as the 'node_ssh' and 'node_windows' recipes do or "Launch slave via execution of command on the Master".
+
+ jenkins_node node[:fqdn] do
+ description "My node for things, stuff and whatnot"
+ executors 5
+ remote_fs "/var/jenkins"
+ launcher "command"
+ command "ssh -i my_key #{node[:fqdn]} java -jar #{remote_fs}/slave.jar"
+ env "ANT_HOME" => "/usr/local/ant", "M2_REPO" => "/dev/null"
+ end
+
+== 'jenkins_job' resource provider
+
+This resource manages jenkins jobs, supporting the following actions:
+
+ :create, :update, :delete, :build, :disable, :enable
+
+The 'create' and 'update' actions require a jenkins job config.xml. Example:
+
+ git_branch = 'master'
+ job_name = "sigar-#{branch}-#{node[:os]}-#{node[:kernel][:machine]}"
+
+ job_config = File.join(node[:jenkins][:node][:home], "#{job_name}-config.xml")
+
+ jenkins_job job_name do
+ action :nothing
+ config job_config
+ end
+
+ template job_config do
+ source "sigar-jenkins-config.xml"
+ variables :job_name => job_name, :branch => git_branch, :node => node[:fqdn]
+ notifies :update, resources(:jenkins_job => job_name), :immediately
+ notifies :build, resources(:jenkins_job => job_name), :immediately
+ end
+
+== 'manage_node' library
+
+The script to generate groovy that manages a node can be used standalone. For example:
+
+ % ruby manage_node.rb name slave-hostname remote_fs /home/jenkins ... | java -jar jenkins-cli.jar -s http://jenkins:8080/ groovy =
+
+= ISSUES
+
+* CLI authentication - http://issues.jenkins-ci.org/browse/JENKINS-3796
+
+* CLI *-node commands fail with "No argument is allowed: nameofslave" - http://issues.jenkins-ci.org/browse/JENKINS-5973
+
+= LICENSE & AUTHOR:
+
+Author:: Doug MacEachern (<dougm@vmware.com>)
+Author:: Fletcher Nichol <fnichol@nichol.ca>
+
+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.
@@ -0,0 +1,113 @@
+#
+# Cookbook Name:: jenkins
+# Based on hudson
+# Attributes:: default
+#
+# Author:: Doug MacEachern <dougm@vmware.com>
+# Author:: Fletcher Nichol <fnichol@nichol.ca>
+#
+# 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.
+#
+
+default[:jenkins][:mirror] = "http://jenkins-ci.org"
+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] = node[:fqdn]
+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] = []
+
+#working around: http://tickets.opscode.com/browse/CHEF-1848
+#set to true if you have the CHEF-1848 patch applied
+default[:jenkins][:server][:use_head] = false
+
+#See Jenkins >> Nodes >> $name >> Configure
+
+#"Name"
+default[:jenkins][:node][:name] = node[:fqdn]
+
+#"Description"
+default[:jenkins][:node][:description] =
+ "#{node[:platform]} #{node[:platform_version]} " <<
+ "[#{node[:kernel][:os]} #{node[:kernel][:release]} #{node[:kernel][:machine]}] " <<
+ "slave on #{node[:hostname]}"
+
+#"# of executors"
+default[:jenkins][:node][:executors] = 1
+
+#"Remote FS root"
+if node[:os] == "windows"
+ default[:jenkins][:node][:home] = "C:/jenkins"
+elsif node[:os] == "darwin"
+ default[:jenkins][:node][:home] = "/Users/jenkins"
+else
+ default[:jenkins][:node][:home] = "/home/jenkins"
+end
+
+#"Labels"
+default[:jenkins][:node][:labels] = (node[:tags] || []).join(" ")
+
+#"Usage"
+# "Utilize this slave as much as possible" -> "normal"
+# "Leave this machine for tied jobs only" -> "exclusive"
+default[:jenkins][:node][:mode] = "normal"
+
+#"Launch method"
+# "Launch slave agents via JNLP" -> "jnlp"
+# "Launch slave via execution of command on the Master" -> "command"
+# "Launch slave agents on Unix machines via SSH" -> "ssh"
+if node[:os] == "windows"
+ default[:jenkins][:node][:launcher] = "jnlp"
+else
+ default[:jenkins][:node][:launcher] = "ssh"
+end
+
+#"Availability"
+# "Keep this slave on-line as much as possible" -> "always"
+# "Take this slave on-line when in demand and off-line when idle" -> "demand"
+default[:jenkins][:node][:availability] = "always"
+
+# "In demand delay"
+default[:jenkins][:node][:in_demand_delay] = 0
+# "Idle delay"
+default[:jenkins][:node][:idle_delay] = 1
+
+#"Node Properties"
+#[x] "Environment Variables"
+default[:jenkins][:node][:env] = nil
+
+default[:jenkins][:node][:user] = "jenkins"
+
+#SSH options
+default[:jenkins][:node][:ssh_host] = node[:fqdn]
+default[:jenkins][:node][:ssh_port] = 22
+default[:jenkins][:node][:ssh_user] = default[:jenkins][:node][:user]
+default[:jenkins][:node][:ssh_pass] = nil
+default[:jenkins][:node][:jvm_options] = nil
+#jenkins master defaults to: "#{ENV['HOME']}/.ssh/id_rsa"
+default[:jenkins][:node][:ssh_private_key] = nil
@@ -0,0 +1,86 @@
+#
+# Cookbook Name:: jenkins
+# Based on hudson
+# File:: node_info
+#
+# Author:: Doug MacEachern <dougm@vmware.com>
+# Author:: Fletcher Nichol <fnichol@nichol.ca>
+
+# 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.
+#
+
+import jenkins.slaves.*
+import jenkins.model.*
+
+def toJSON(node) {
+ if (node instanceof Map) {
+ return "{" + node.collect { k,v -> "\"${k}\":" + toJSON(v) }.join(", ") + "}"
+ }
+ else if (node instanceof String) {
+ return "\"${node}\""
+ }
+ else {
+ return node
+ }
+}
+
+slave = Jenkins.instance.getNode(this.args[0]) as Slave
+
+if (slave == null) {
+ println "{}"
+}
+else {
+ node = [
+ "name" : slave.name,
+ "description" : slave.nodeDescription,
+ "remote_fs" : slave.remoteFS,
+ "executors" : slave.numExecutors.toInteger(),
+ "mode" : slave.mode.toString(),
+ "labels" : slave.labelString,
+ "availability" : slave.retentionStrategy.class.name.tokenize('$').get(1),
+ ]
+
+ if ((env = slave.nodeProperties.get(EnvironmentVariablesNodeProperty.class)?.envVars)) {
+ node["env"] = env
+ }
+
+ if (slave.retentionStrategy instanceof RetentionStrategy.Demand) {
+ retention = slave.retentionStrategy as RetentionStrategy.Demand
+ node["in_demand_delay"] = retention.inDemandDelay
+ node["idle_delay"] = retention.idleDelay
+ }
+
+ launcher = slave.launcher
+ if (launcher instanceof CommandLauncher) {
+ node["launcher"] = "command"
+ node["command"] = launcher.command
+ }
+ else if (launcher instanceof JNLPLauncher) {
+ node["launcher"] = "jnlp"
+ }
+ else {
+ node["launcher"] = "ssh"
+ node["host"] = launcher.host
+ node["port"] = launcher.port
+ node["username"] = launcher.username
+ if (launcher.password != null) {
+ node["password"] = launcher.password
+ }
+ node["private_key"] = launcher.privatekey
+ node["jvm_options"] = launcher.jvmOptions
+ }
+
+ println toJSON(node)
+}
@@ -0,0 +1 @@
+deb http://pkg.jenkins-labs.org/debian binary/
Oops, something went wrong.

0 comments on commit c7e1785

Please sign in to comment.