Showing posts with label jenkins. Show all posts
Showing posts with label jenkins. Show all posts

Friday, January 18, 2019

#Throwback: A batch script to clone or update Project from a Git repository

Background:The use-case behind this was that we could not checkout our project from Git repository in Jenkins for reasons I could not remember. I'm just publishing this here as an archive for future reference in case I encounter something of the same nature.
  1. There should be curl in the system to verify the URLs
  2. Set the variables, set proxy depending on IP of the Jenkins slave. We had slaves within a certain subnet which needs proxy for them to be able to connect to our Git repositories.
  3. Perform connection checks 
  4. Proceed with clone if project is not yet existing in the machine, update if already existing 
  5. Create backup of successful clone/update



Tuesday, July 24, 2018

#Throwback: A script that will launch Jenkins slave to a remote Windows PC

Background:There are times when our Master Jenkins would go offline due to various reasons (network issues usually). Our Slave machines will then end up with their Jenkins agents in a dead state basically having to manually intervene to recover the connection. 


Assumptions:

  • Windows-to-Windows only since it uses Windows specific tool (PsExec.exe).
  • Target Slave machine has svn command-line client installed because the script would make slave PC to checkout the scripts first from an svn repo.
  • Will only work with lower versions of Jenkins (specifically, Jenkins versions that are built against Java 7 and below)
-- Modify as per your need --


Approach:

  1. The main script (slave_launcher.bat) would connect to the remote Slave Windows machine via PsExec.exe
  • Checks out the tool in the remote slave server
  • Executes kill.bat - which kills any running "javaw.exe" process. Our machines launch javaw.exe for Jenkins only. If your machine is using javaw.exe for other purposes, you have to modify this part.
  • Executes generate_slave.bat - generates the new slave bat file with values supplied in main script then runs it.

Main Script: slave_launcher.bat
Sample command:  slave_launcher.bat http://localhost:8080 10.69.243.14 user1 password123 svn://svnhost:5800/CI_Script/batch/ci_slave_launcher

Final notes: 

  • PsExec.exe is glitchy. It may not run at first attempt but could become successful on the second try. Test it out part by part first.
  • Creating a job in your Master jenkins for this script can be helpful. 
  • Again, modify as per your need, ex replacing "svn checout" with "FTP transfer", etc. This was just an impromptu script that we had to do because of the sheer number of slaves that we had to maintain.