The purpose of this exercise was to be able to quickly deploy Salesforce metadata to multiple environments in parallel, in order to save some time and effort. Occasionally you end up working on a project where continuous delivery is not worth setting up, or you need to quickly migrate something to all sandboxes without touching production. There could be a lot of other reasons where you need to do this very quickly and you don't want to perform a repetitive deployment to each environment.
Let me answer a couple of questions before I start:
- Yes, you can use your IDE or ANT to deploy to multiple environments, though you'd have to do it one by one
- Yes, you can setup a CI tool and automate this whole thing, but that's not the goal of this exercise
- Yes, you can use change sets, but they are painful and it takes forever to upload/deploy and re-iterate. You gotta love the famous "This change set is not currently available. Recently uploaded change sets may take up to 30 minutes to be available for deployment. Please wait 30 minutes and try deploying your change set again."
- Yes, SFDX is on the way, still in development. At the time it wasn't available so I had to find a workaround
I even stumbled upon this IDEA - I guess it's just this guy and myself who are trying to do this...
Anyway, looking at how the ANT Migration Tool works, an instant light bulb spawned on top of my head - I can have multiple configurations and run multiple sessions in parallel. First I tried it manually of course, and then I wrote a quick shell script to automate it.
Disclaimer: this is tailored for OS X. With some minor tweaks it can be easily ported to Linux too. I haven't attempted to do it on Windows, though it should be easy to follow the concept and do something similar using PowerShell and some session management modules similar to tmux/screen.
Before you begin, ensure you have the following prerequisites:
Boom. Now you can pass the folder names (aliases for your orgs) as parameters to the script and it will initiate multiple `deploy` actions to each one of them. Also a log file will be created for each org under /logs.
Example:
`cd ~/YOURFOLDER`
`./deploy.sh sandbox1 sandbox2 sandbox3 sandbox4`
or
`./deploy.sh all`
If you want to deploy to all environments which are part of the /targets structure
This is very basic stuff to get you going. Obviously you can extend this and add all sorts of checks for the parameters, as well as initiate different actions specific to the target org etc.
Let me know in the comments below if you have any thoughts, comments, or even a better workaround. I'd love to hear more.
Let me answer a couple of questions before I start:
- Yes, you can use your IDE or ANT to deploy to multiple environments, though you'd have to do it one by one
- Yes, you can setup a CI tool and automate this whole thing, but that's not the goal of this exercise
- Yes, you can use change sets, but they are painful and it takes forever to upload/deploy and re-iterate. You gotta love the famous "This change set is not currently available. Recently uploaded change sets may take up to 30 minutes to be available for deployment. Please wait 30 minutes and try deploying your change set again."
- Yes, SFDX is on the way, still in development. At the time it wasn't available so I had to find a workaround
I even stumbled upon this IDEA - I guess it's just this guy and myself who are trying to do this...
Anyway, looking at how the ANT Migration Tool works, an instant light bulb spawned on top of my head - I can have multiple configurations and run multiple sessions in parallel. First I tried it manually of course, and then I wrote a quick shell script to automate it.
Disclaimer: this is tailored for OS X. With some minor tweaks it can be easily ported to Linux too. I haven't attempted to do it on Windows, though it should be easy to follow the concept and do something similar using PowerShell and some session management modules similar to tmux/screen.
Before you begin, ensure you have the following prerequisites:
- Screen (or similar multiplexer). If you have Homebrew then you're set with just `brew install screen`
- The following folder structure:
- codepkg contains all the metadata you want to move around
- logs is where the script will output the logs for each deployment
- targets is a container which has a sub-folder for each environment. In each of these sub-folders you need to add the Force.com migration tool configuration files. Note that the name will be used as a parameter when executing the script. Give it a meaningful name so that you know where you're deploying to.
- The following shell script:
- Save it and run `chmod +x scriptname` from your command line
Boom. Now you can pass the folder names (aliases for your orgs) as parameters to the script and it will initiate multiple `deploy` actions to each one of them. Also a log file will be created for each org under /logs.
Example:
`cd ~/YOURFOLDER`
`./deploy.sh sandbox1 sandbox2 sandbox3 sandbox4`
or
`./deploy.sh all`
If you want to deploy to all environments which are part of the /targets structure
This is very basic stuff to get you going. Obviously you can extend this and add all sorts of checks for the parameters, as well as initiate different actions specific to the target org etc.
Let me know in the comments below if you have any thoughts, comments, or even a better workaround. I'd love to hear more.
No comments:
Post a Comment