January 4, 2021
Estimated Post Reading Time ~

AEM Automation – Deploy & Replicate Package

Guide:

Following is the Powershell script that will automate the process of uploading and install the AEM package to Author Instance. The uploaded package will be replicated to publish instances using cURL. Following are the parameters,

param( 
[String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_USER="admin", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_PASS="admin", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$AEMPORT="4502", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$HOSTNAME="localhost", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$PKGNAME="aemdev.ui.apps-1.0-SNAPSHOT.zip", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$PKGPATH="C:\Users\SKYDEVOPS\Documents\AEMMVN\aemdev\ui.apps\target\${PKGNAME}", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$GCURL="http://${HOSTNAME}:${AEMPORT}/crx/packmgr/service.jsp", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$RCURL="http://${HOSTNAME}:${AEMPORT}/crx/packmgr/service/script.html/etc/packages/aemdev/${PKGNAME}?cmd=replicate", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CURLEXE="C:\tools\curl761\bin\curl.exe" ) 

Following is the cURL command that will Install-Package on AEM instance, which needs username and password to authenticate package installation, also a path to the package that needs to be installed

Write-Output "Installing APPS Package" cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASS}" -F file=@"$PKGPATH" -F name="AEMDEV" -F force=true -F install=true "$GCURL" | Out-Null Write-Output "Package Installation Complete"

Following is the cURL command that will replicate the installed package to all the publishers

Write-Output "Replicating Package" cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASS}" -X POST $RCURL Write-Output "Replication Complete"

Following is the entire script

# Parameters param( [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_USER="admin", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CQ_PASS="admin", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$AEMPORT="4502", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$HOSTNAME="localhost", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$PKGNAME="aemdev.ui.apps-1.0-SNAPSHOT.zip", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$PKGPATH="C:\Users\SKYDEVOPS\Documents\AEMMVN\aemdev\ui.apps\target\${PKGNAME}", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$GCURL="http://${HOSTNAME}:${AEMPORT}/crx/packmgr/service.jsp", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$RCURL="http://${HOSTNAME}:${AEMPORT}/crx/packmgr/service/script.html/etc/packages/aemdev/${PKGNAME}?cmd=replicate", [String][parameter(Mandatory=$False,ValueFromPipeline=$False)]$CURLEXE="C:\tools\curl761\bin\curl.exe" 

# Installing Packages 
Write-Output "Installing APPS Package" 
cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASS}" -F file=@"$PKGPATH" -F name="AEMDEV" -F force=true -F install=true "$GCURL" | Out-Null 
Write-Output "Package Installation Complete" 

# Replicating package 
Write-Output "Replicating Package" 
cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASS}" -X POST $RCURL 
Write-Output "Replication Complete"


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.