38

I would like to have continous integration (with Jenkins) for my apex code in order to run them automatically after each push to my git repository. Does anyone know a way how to do that?

1

8 Answers 8

26

There are a couple of decent Dreamforce presentations here: Team Development: Possible, Probable, and Painless and Continuous Integration in the Cloud.

We ran into some issues with this in practice and there was no way to get true automation (i.e., set it and forget it). We were also setting it up with Selenium.

Here were the issues that I remember.

  1. Some features aren't supported in the metadata API and cannot be moved via the ant migration. If you have any unit tests that work with those features, you have to manually work on your CI org.

  2. Deletions are harder to maintain. You have to manually update and apply a destructiveChanges.xml file or replicate the deletion in the CI org.

  3. We ran into a situation where some metadata XML files had 'invalid' data in them. The suggested solution was to build a post checkout script that manipulates the offending XMLs into valid XMLs. Not ideal.

  4. On projects, we wanted to track just our changes and push out just our changes in source control. In theory, this would allow much easier rebaselining. This would have required more manual maintenance of XML files (e.g., 2 new fields added on Account and only want to push those 2 fields not all (*) fields).

My conclusion is that it is worth doing if you can get it set up, but if you are working on shorter term projects and don't have a decent amount of time budgeted in for it, it probably isn't worth setting up.

Although it isn't CI, check out http://developer.force.com/cookbook/recipe/automated-unit-test-execution. You could set it up to run every hour or something like that.

5
  • 1
    +1 for issue #1. If your codebase is dependent on time-dependent workflows, recursive workflow, M-D rehoming, etc, it's quite difficult to fully automate a fresh install. You can do it with Selenium but it's a bit of a pain. I wish SFDC would put some more resources towards giving developers an experience more competitive with the likes of Java/.NET/Rails etc for CI, but that seems unlikely in the near future.
    – jkraybill
    Commented Aug 23, 2012 at 5:07
  • Another issue I'd add: if you're dealing with managed packages, automating the "build" and install of a new package is even more difficult. We've given up and just do periodic manual upload/install/test runs, including automated tests and a manual smoke test.
    – jkraybill
    Commented Aug 23, 2012 at 5:10
  • 1
    Worth noting is that, at a minimum, the metadata from an org in which you are developing should be backed up nightly so you aren't SOL if someone refreshes by accident. For this, it is easy to set up a simple Jenkins job that runs each night and pulls down all of the metadata and checks it into a repository. Commented Aug 23, 2012 at 9:59
  • 1
    Regarding issue 2, you might want to take a look at the undeploy tool here, github.com/financialforcedev/df12-deployment-tools. The aim of this tool is to clear out your designated CI org prior to pushing in your org your latest build. Commented Nov 11, 2012 at 13:04
  • None of these YouTube links work anymore "Team Development: Possible, Probable, and Painless and Continuous Integration in the Cloud."
    – Arpi Jakab
    Commented Dec 7, 2016 at 16:58
10

We're trying to set up the same, and while we still have to get some configurations right, I do think we have gotten the overall setup.

Using github plugins to jenkins you can poll for repository changes. We're using ssh keys between jenkins and github as authentication.

Jenkins uses ANT, and so does the force.com migration tool, you can use the deploy xml file you'd write for the migration tool to run with ant from jenkins, this can include that all tests need to be ran.

I believe this is the setup used by quite some teams already, yet no one seems to have written a full description on how to set it up publicly (at least, I've not found one). I may give it a try once we have our system fully running

0
8

I'm doing a presentation at Dreamforce '12 on this exact subject: Team Development and Release Management for ISVs

In the session I'll outline going through a complete CI life-cycle (develop, version control, build, package, deploy to AppExchange).

This session is mostly geared to AppExchange releases but could easily be a good building block for anyone whom wants to do CI. I'm hoping to get the Github repo up which will include a link to the Amazon AMI preconfigured like the one we use to manage multiple devs and builds with Jenkins at Bracket Labs

5
  • Look forward to it! Commented Aug 20, 2012 at 18:17
  • Is there any related document or video you can share so that we can also setup CI
    – Ugesh Gali
    Commented Sep 27, 2012 at 17:54
  • Ugesh: see github repo here: github.com/BracketLabs/… - this demo will get you started. And I will support working with it. As for the video, I don't know if it's available yet. Commented Sep 27, 2012 at 17:59
  • Thank you very much. All the images are broken in the github repo.
    – Ugesh Gali
    Commented Sep 27, 2012 at 18:07
  • Just fixed them when I saw that before (I took them down cause they were causing issues (with the Eclipse IDE's memory heap) ... so I need to make a note to delete them from the src directory after you clone it. Commented Sep 27, 2012 at 19:13
8

Check out the sample code for the ApexTestQueueItem sObject here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_unit_tests_running.htm

and the more involved cookbook recipe: http://developer.force.com/cookbook/cookbookRecipeSource?id=a1V30000000AV1vEAG

3

Download the Force.com Migration Toolkit and start tinkering with it. The salesforce-ant jar contains a component for deploying code, but that component also allows you to run either all tests or individual tests (specified by a child element under the deploy component).

Unfortunately, there is no component for explicitly running tests, so it looks like (I havent tried this myself) that you must deploy something in order to run the tests.

Hope that helps.

More info on the migration toolkit: http://www.salesforce.com/us/developer/docs/daas/salesforce_migration_guide.pdf

1

RABIT [ Rapid Automated Build Install and Test ] has a salesforce specific edition which has all the CI needs like meta deployment , Apex Unit Testing , scheduled dataloading bundled into a product . you can visit rabitforce.com for the documentation

0

I feel that continuous integration for Salesforce is a lot of work given the nature of the platform, metadata, cloud based architecture with everything being routed by web services. However, I have used Flosum and it is an excellent solution for automated builds, much better than using Jenkins for Salesforce. We found that it not only automates the apex tests, but also helps with many activities for Salesforce release management. I would encourage you to try it out.

0

I wrote an article describing how to achieve this: https://apexandbeyond.wordpress.com/2017/03/04/continuous-integration-for-salesforce/ We are using this in our company and deploying more than 10000 components every month including objects, fields, workflow and classes

2
  • If the article answers the question, please cite the relevant content here. You can edit your post to improve it in this way. Links can break over time, so answers that contain only links are often deleted.
    – Adrian Larson
    Commented Mar 11, 2017 at 16:11
  • I get that @AdrianLarson, but is not something that can be explained in one comment in here, that's why I put the link to the full explanation Commented May 5, 2017 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .