I’m finally getting on this Jenkins bandwagon. I could have used TeamCity, but didn’t grab that chance when it came by. But free is good, so Jenkins, will you be my friend? I created a brand new page for you.
My Jenkins server is on windows.
Installation was a breeze, but I swear there was no place where it asked where to install it to. It went into program files(x86)\…. I wanted to move it to another drive. I set JENKINS_HOME env var on the system, restarted Jenkins, no use. You need to edit jenkins.xml and set the value in JENKINS_HOME in that file. I worried I was changing the value of BASE, but this BASE seems to be defined elsewhere.
Perforce is our scm system. I couldn’t find the Perforce plugin in the list of available plugins, so downloaded it. It downloaded as a .zip file. Rename this as perforce.hpi, go to the Advanced panel on the plugin manager and upload the plugin.
Configuring Jenkins – there are so many variables!! What the heck is parametrization etc? Configured a bare minimum build, using a view map type, I put workspace-name in the rhs of the view map and executing a batch script. The value for workspace (client) can’t be null, the workspace created by Jenkins is invalid otherwise. This value gets substituted for the workspace-name in the created clientspec. I’ve also set it to poll scm every minute 0 * * * *. I thought the log was timestamped for each statement, unfortunately not 😦
Now onto figuring out how to have multiple nodes. Really cool for windows node setup : https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines. I needed to install JRE on this box to open the jnlp. Used the launch through Java option for starting the node.
tbd : linux node setup
How do we do this in Jenkins?:
* Build each change – Hard to believe – there’s no obvious method to build each change in source.
* Copy a job – many ways to skin this cat. Copy an existing job from the New Job interface, copy the job directory on the server…
Must have plugins:
https://wiki.jenkins-ci.org/display/JENKINS/Configuration+Slicing+Plugin – mass edit jobs. Lifesaver!
Interesting Plugins:
https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin#ScriptlerPlugin-Description – deploy scripts. Need to get amped on Groovy. So much to learn, daunted, not energized 😦
Build Flow plugin – https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin
XTrigger plugin – https://wiki.jenkins-ci.org/display/JENKINS/XTrigger+Plugin
Groovy Scripts:
Reload configuration from disk from http://stackoverflow.com/questions/5216552/does-anyone-know-how-to-reload-hudson-configuration-without-restarting:
Works for me. Now why the heck won’t Jenkins reload config from disk when I click the button is the quesiton which I don’t have time to research 😦
UI: Copy the following script in your Jenkins Script page, for instancehttp://www.mydomain.com/jenkins/script
import java.io.InputStream;
import java.io.FileInputStream
import java.io.File;
import javax.xml.transform.stream.StreamSource
def hudson = hudson.model.Hudson.instance;
//to get a single job
def job = hudson.model.Hudson.instance.getItem('my-job');
//for(job in hudson.model.Hudson.instance.items) {
if (job.name == "my-job") {
def configXMLFile = job.getConfigFile();
def file = configXMLFile.getFile();
InputStream is = new FileInputStream(file);
job.updateByXml(new StreamSource(is));
job.save();
}
//}
CLI: You can save the above script in a file and execute it remotely over CLI as a groovy script:
java -jar jenkins-cli.jar -s http://www.mydomain.com/jenkins groovy reload-job.groovy
References:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI (CLI) http://javadoc.jenkins-ci.org/hudson(API)
Find jobs that run on a label: http://ServerIP:8080/label/LABELNAME/api/json?pretty=true
Find machine/label info: from https://wiki.jenkins-ci.org/display/JENKINS/Display+Information+About+Nodes
for (aSlave in hudson.model.Hudson.instance.slaves) { println('===================='); println('Name: ' + aSlave.name); println('getLabelString: ' + aSlave.getLabelString()); println('getNumExectutors: ' + aSlave.getNumExecutors()); println('getRemoteFS: ' + aSlave.getRemoteFS()); println('getMode: ' + aSlave.getMode()); println('getRootPath: ' + aSlave.getRootPath()); println('getDescriptor: ' + aSlave.getDescriptor()); println('getComputer: ' + aSlave.getComputer()); println('\tcomputer.isAcceptingTasks: ' + aSlave.getComputer().isAcceptingTasks()); println('\tcomputer.isLaunchSupported: ' + aSlave.getComputer().isLaunchSupported()); println('\tcomputer.getConnectTime: ' + aSlave.getComputer().getConnectTime()); println('\tcomputer.getDemandStartMilliseconds: ' + aSlave.getComputer().getDemandStartMilliseconds()); println('\tcomputer.isOffline: ' + aSlave.getComputer().isOffline()); println('\tcomputer.countBusy: ' + aSlave.getComputer().countBusy()); //if (aSlave.name == 'NAME OF NODE TO DELETE') { // println('Shutting down node!!!!'); // aSlave.getComputer().setTemporarilyOffline(true,null); // aSlave.getComputer().doDoDelete(); //} println('\tcomputer.getLog: ' + aSlave.getComputer().getLog()); println('\tcomputer.getBuilds: ' + aSlave.getComputer().getBuilds()); }
Restart Jenkins: Honestly, it took me this long to find this – http://jenkins-server/restart restarts the damn thing!
Leave a comment