This post has been migrated from www.experimentsincode.com, we apologise if some of the images or content is missing

The latest release of Razl (2.5) contains script mode, see Mike Shaw's blog post and my own blog post on this, "Coming Soon – Razl Script Mode". One feature that these blogs posts don't detail is the parameter support we have added to Razl script mode. This allows you to pass parameters from the command line to your script, these parameters can then be used to replace placeholders in your script. To demo this I am going to create a script that will allow me to copy content and media library items from my live CMS box to another environment. I want to be able to pass in the target URL and path for the instance I am copying to because I create lots of instances and need to perform this task a lot. My script looks like this:
<razl>
	<connection name="Live" readOnly ="true" install="false">
		<url>http://cms.tds</url>
		<accessGuid>757cb84a-04c3-4bac-a95e-d05b7b05eb11</accessGuid>
		<database>master</database>
	</connection>
	<connection name="Local" readOnly ="false" install="true">
		<url>$(url)</url>
		<accessGuid>757cb84a-04c3-4bac-a95e-d05b7b05eb11</accessGuid>
		<database>master</database>
		<path>$(path)</path>
	</connection>
	<operation name="CopyAll" source="Live" target="Local">
		<!--/sitecore/content-->
		<parameter name="itemId">{0F6AE67A-74C4-4E0F-BC4C-774F01E19AFE}</parameter>
		<parameter name="overwrite">true</parameter>
	</operation>
	<operation name="CopyAll" source="Live" target="Local">
		<!--/sitecore/media-->
		<parameter name="itemId">{15451229-7534-44EF-815D-D93D6170BFCB}</parameter>
		<parameter name="overwrite">true</parameter>
	</operation>	
</razl>
The important part of this script is the local connection:
	<connection name="Local" readOnly ="false" install="true">
		<url>$(url)</url>
		<accessGuid>757cb84a-04c3-4bac-a95e-d05b7b05eb11</accessGuid>
		<database>master</database>
		<path>$(path)</path>
	</connection>
Here you can see that the local connection contains $(url) and $(path), these are the placeholders that will be replaced by my command line parameters. Your placeholders can be any name but must be wrapped in $() and contain no spaces. Now I have this script I can specify the values to use with the /p switch:
Razl /script:copy.xml /p:url=http://dev.tds;path=C:\Sitecore\dev.tds\Website
This gives me great flexibility to reuse my script without having to modify it every time something changes. I can also share this with other members of the team who might also want to pull down data from live. We could also use this as part of a build process, but to find out more about that you will have to attend the Sitecore User Group Conference and attend my presentation on Sitecore Nirvana - Continuous Deployment.
comments powered by Disqus