Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Jenkins Swarm Slaves on Windows using Puppet Linux

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):
  1. Download Swarm jar
  2. Download winsw from Kohsuke
  3. Rename winsw to jenkins_swarm.exe
  4. Create jenkins_swarm.xml
  5. Run jenkins_swarm.exe install
  6. Start service
Now for the details

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 Trackbacks

  1. No Trackbacks

0 Comments

Display comments as (Linear | Threaded)
  1. No comments

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

What is the primary language of this blog? (Anti-SPAM question)


Submitted comments will be subject to moderation before being displayed.