Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distribute test script to slaves with same build

Tags:

jenkins

Our current setup consist of a single master controlling several slave machine. Usually, the master would issue the test scripts to slaves based on list. Which ever machine is finish a script or idle, it would continue down the list. All of these are tested against a same single build.

We are moving towards CI way and would wish to do something similar to our current plans. I would think it could work the same whereby the master would build, then distribute to the slave for testing. How would this be done?

edit: Just to clarify my position, I have not use Jenkins before, therefore the lack of knowledge for it. Before flaming me into oblivion, I just need someone to point me to the right direction, not asking for a spoon feed solution.

like image 329
freonix Avatar asked Oct 10 '12 15:10

freonix


2 Answers

Since you didn't accept hyde's response, I'll assume you're looking for a more detailed answer. First, if you're new to Jenkins I highly recommend Jenkins: The Definitive Guide. Jenkins isn't difficult to use, but it can be hard to get started. That book provides a nice guided tour from the beginning into some of the more intricate parts of running a Jenkins installation. Now on to your question. Jenkins allows you to try things out very quickly without having to really "install" it, so follow along here. You'll also want access to a second computer to make the temporary slave (don't worry, there's no real installation, so just use a coworker's computer).

These instructions look long, but only because I'm walking through every single step. This won't take much time. Also, feel free to click on the little question marks next to all of the fields in Jenkins as we go. By the way, when I quote something, type what's inside the quotes but not the quotes themselves.

  1. Go to Meet Jenkins and scroll down to the Launch button to start Jenkins without installing anything.
  2. Go to http://localhost:8080/. Look! Jenkins is running!
  3. On the left, click Manage Jenkins, then click the Manage Nodes item.
  4. On the left, click New Node. Name it "Foo", select "Dumb Slave", and click OK.
  5. Set "# of executors" to 1 (it's the number of builds you want this slave to run concurrently).
  6. Set "Remote FS root" to "c:\jenkins" or "/tmp" (this will create some files on the slave machine, so use a directory that has write permissions).
  7. Set "Labels" to "tester"
  8. Set "Launch method" to "Launch slave agents via Java Web Start" (you probably don't want to do this in production, but it will allow us to bring up a slave quickly).
  9. Click Save
  10. Click on Jenkins in the upper left corner to go back to the main page.
  11. Click New Job on the left.
  12. Name the job "My build" and select "free-style software project" and click OK.
  13. Check Restrect where this project can be run and type "master" for the label (it should even auto-complete). This makes the build only run on the master.
  14. Towards the bottom click Add build step.
  15. If your master (the current machine) is a Windows machine, select "Execute Windows batch command", otherwise, select "Execute shell".
  16. Either way, for the command type "echo Building". This isn't necessary, but it allows you to see that the build really did something that you told it to do.
  17. At the bottom of the screen, click Save.
  18. You should now be at the "Project My Build" page. Click the Build Now link on the left. Since the build barely does anything, it finishes almost instantly. An entry appears in the history with a blue circle, indicating that the build was successful.
  19. Go back to the main Jenkins screen and add a New Job.
  20. Name this one "My test", make it another "free-style software project", and click OK.
  21. Again, check "Restrict where this project can be run", but make the label "tester" (again, it should auto-complete).
  22. Scroll down and click Add build step again. Select "Windows batch" or "shell" depending on what the slave computer (e.g., your coworker's computer) is.
  23. Type "echo Testing"
  24. Click Save down at the bottom.
  25. Now for the fun part. Go to your other computer (or tell a coworker that their headlights are on and use their computer). Open the web browser and go to http://your-masters-ip-address:8080/
  26. Click Manage Jenkins, and then Manage Nodes.
  27. Click Foo, and click the Launch button. Click through any security/"are you sure" warnings, and you should see a little window saying Jenkins is connected. Now your slave is running.
  28. Go back to your master computer, go to your Jenkins home screen, and click My test in the list of builds.
  29. On the left, click Build Now. This will take a little longer, because it has to contact the slave and farm out the job, but it should finish and add the build to the history.
  30. Click the entry in the build history. Then, on the left, click Console Output.
  31. The log should say that the build was remotely executed on Foo, and have the echo statement. Woohoo! We now have remote builds working.
  32. Lastly, we'll link the builds together. Navigate your way back to "My build" and click Configure on the left.
  33. In the Post-build Actions section, click Add post-build action, and select "Build other projects". Type "My test" in the field (it should autocomplete). Click Save.
  34. Go to the Jenkins main screen, and click the clock/play icon to the right of "My Builds". If you watch carefully, you may see the jobs appear in the "Build Queue" or the "Build Executor Status" on the left.
  35. Wait a minute or so, and then refresh the page, and you should see the "Last Success" time for both of your builds update. Clouds should part, and you should hear angels singing, but don't celebrate just yet.

You now have a master doing the "build" and a slave doing the "test", and a build triggers the test. You could add more slaves and so long as they have the label "tester", the build server will auto-distribute. You could also have many tests following the build, and have the build trigger all of them. That's all the easy stuff, the thing that requires some elbow grease is getting Jenkins to run your build and tests. Start small and work your way up. Oh, and seriously, go buy that book I linked to (it's available in dead-tree and DRM-free ebook, and no, I don't have any connection to O'Reilly or the author, it's just a very useful book) so you have an idea of what Jenkins can do and how best to fit it with your system and what you want.

like image 130
Tom Panning Avatar answered Oct 17 '22 17:10

Tom Panning


Is this what you mean:

  1. Go to slave node configuration, and give slave appropriate label, like "unittest". Repeat this for all slaves you want for unit tests (note that slave can have many labels if needed).

  2. Go to job configuration, tick "restrict where this job can run", type "unittest" there.

Also read help texts of these fields!

For more advanced/complex CI setup, also check out node label parameter plugin, if you want to parametrize where a job can run.

like image 44
hyde Avatar answered Oct 17 '22 15:10

hyde