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.

Sunday, December 28, 2014

1418316618 - Learning

The "I'm a fast learner" attitude covers only a portion of your competence when it comes to learning. Basically, you should at least assess yourself with these questions:

How much have you learned so far?
  • The world does not work on enumerations. Terminologies can be reviewed again from references. Meaningless details either cloud your judgment or just plainly distracts you.
  • If you learned it with quality, you will not have a problem explaining an idea you learned 5 years ago.

How well you can teach yourself?
  • If you are confused, you just have to find how it fits the big picture. No matter how complex that is, it still started from something so simple. Therefore, master the fundamentals first.

How efficient you are in applying what has been learned?
  • Being resourceful and still be creative. What are you able to produce with limited information?
  • Remember that knowledge and wisdom are two different things.

How do you take care of your brain?
  • Again, information overload is not healthy.
  • Multitask at your own risk. As it turns out, parallel computing does not apply on humans. Technically, it is just "task-switching" and it is inefficient because it usually produces low quality output.
  • Ask wisely. If it starts with "why" or "how", try to figure it yourself as much as possible. Your learning ability must not create a dependency from other people.