Jenkins Swarm Slaves on Windows using Puppet
Posted by Admin • Monday, October 12. 2015 • Category: DevOps, Linux
Jenkins Swarm plugin is great, and instrumentation for Linux is fairly well-known, but what about Windows? Here is one approach for setting it up as a windows sevice (what we want Puppet to do):
The puppet manifest to do this will do all of the above in order. Here are some selected fragments (your provide all the values and winsw.exe in files/ dir of the module):
- Download Swarm jar
- Download winsw from Kohsuke
- Rename winsw to jenkins_swarm.exe
- Create jenkins_swarm.xml
- Run jenkins_swarm.exe install
- Start service
The puppet manifest to do this will do all of the above in order. Here are some selected fragments (your provide all the values and winsw.exe in files/ dir of the module):
$swarm_command_line = "-jar $swarm_destination_directory\\$swarm_destination_file -username $master_user -password $master_pass -mode exclusive -name ${hostname} -executors 1 -master ${master} -labels \"${labels}\" ${extra_swarm_args} "
file{ $swarm_destination_directory:
ensure => directory,
}
# Create a copy of Kohsuke's wrapper
# https://github.com/kohsuke/winsw
# and it's configuration
file {$swarm_wrapper_conf:
content => template("${module_name}/jenkins-swarm.xml.erb"),
}
file {$swarm_wrapper_exe:
source => "puppet:///modules/${module_name}/winsw-1.18-bin.exe",
require => File[$swarm_wrapper_conf]
}
# Download swarm
download_file { 'Swarm Jar':
url => $swarm_url,
destination_directory => $swarm_destination_directory,
destination_file => $swarm_destination_file,
require => File[$swarm_destination_directory]
}
exec { 'Create Swarm Windows Service':
path => ['c:/windows/system32'],
command => "$swarm_wrapper_exe install",
unless => "sc query ${swarm_winservice_name}",
require => [Download_file['Swarm Jar'], File[$swarm_wrapper_exe]]
}
Config
Now for the template for jenkins_swarm.xml
<service>
<id>jenkins_swarm</id>
<name>Jenkins Slave via swarm <%= swarm_version %></name>
<description>This service runs a Jenkins slave. It is created via puppet.</description>
<!--<env name="JENKINS_HOME" value="%BASE%"/>-->
<executable>java</executable>
<arguments><%=swarm_command_line%></arguments>
<logmode>rotate</logmode>
<!-- if we want the slave process to run as a specific local user -->
<serviceaccount>
<domain>.</domain>
<user><%=user%></user>
<password><%=pass%></password>
<allowservicelogon>true</allowservicelogon>
</serviceaccount>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="10 sec"/>
</service>
0 Comments
Add Comment