Skip to content

AEM — Download, Install & Replicate Package

SYNOPSIS:

Following is the guide to download AEM package from an Author instance and deploy and install the package on another instance using curl and powershell on windows machines and curl and bash on *nix machines.

TOOLS USED:

  • Powershell
  • cURL
  • Sublime Text
  • Windows 10
  • Mac OSX
  • Bash
  • Jenkins
  • iTERM

GUIDE:

Step-01: Jenkins – Project Name – Housekeeping

Screen Shot 2018-09-29 at 7.10.23 PM

Step-02: Jenkins Parameter – Download PKG – Hostname

Screen Shot 2018-09-29 at 7.10.36 PM

Step-03: Jenkins Parameter – Install PKG – Hostname

Screen Shot 2018-09-29 at 7.10.43 PM

Step-04: Jenkins Parameter – Package Name

Screen Shot 2018-09-29 at 7.10.53 PM

Step-05a: Jenkins – Build Step – Powershell Script – If Jenkins host is based of Windows

param(
     [Parameter()][ValidateNotNullOrEmpty()][int]$AEMPORT        =   4502,
     [Parameter()][ValidateNotNullOrEmpty()][String]$CQ_USER     =   "admin",
     [Parameter()][ValidateNotNullOrEmpty()][String]$HOSTNAMED   =   "$Env:D_Host",
     [Parameter()][ValidateNotNullOrEmpty()][String]$CQ_PASSD    =   "admin",
     [Parameter()][ValidateNotNullOrEmpty()][String]$HOSTNAMEI   =   "$Env:I_Host",
     [Parameter()][ValidateNotNullOrEmpty()][String]$CQ_PASSI    =   "admin",
     [Parameter()][ValidateNotNullOrEmpty()][String]$PKGNAME     =   "$Env:PKG_NAME",
     [Parameter()][ValidateNotNullOrEmpty()][String]$PKGPATH     =   ".\${PKGNAME}",
     [Parameter()][ValidateNotNullOrEmpty()][String]$CURLEXE     =   "C:\tools\curl761\bin\curl.exe",
     [Parameter()][ValidateNotNullOrEmpty()][String]$ICURL       =   "http://${HOSTNAMEI}:${AEMPORT}/crx/packmgr/service.jsp",
     [Parameter()][ValidateNotNullOrEmpty()][String]$DCURL       =   "http://${HOSTNAMED}:${AEMPORT}/etc/packages/aemgit/${PKGNAME}",
     [parameter()][ValidateNotNullOrEmpty()][String]$RCURL = "http://${HOSTNAMEI}:${AEMPORT}/crx/packmgr/service/script.html/etc/packages/aemdev/${PKGNAME}?cmd=replicate"
 )

 # Download Package
 Write-Host " "
 Write-Host -ForegroundColor Yellow ">>>> Downloading APPS Package"
 cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASSD}" "${DCURL}" --Host $PKGPATH
 Write-Host " "
 Write-Host -ForegroundColor Green ">>>> Package Downlaod Complete"

 # Installing package
 Write-Host " "
 Write-Host -ForegroundColor Yellow ">>>> Uploading and installing Package"
 cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASSI}" -F file=@"$PKGPATH" -F name="AEM_GIT_APP" -F force=true -F install=true "${ICURL}" | Out-Null
 Write-Host " "
 Write-Host -ForegroundColor Green ">>>> Installation Complete"

 # Replicating package
 Write-Host " "
 Write-Host -ForegroundColor Yellow "Replicating Package"
 cmd.exe /c $CURLEXE -u "${CQ_USER}:${CQ_PASSI}" -X POST $RCURL
 Write-Host -ForegroundColor Green "Replication Complete"
 Write-Host " "

 # Remove the downloaded package from workspace
 Write-Host " "
 Write-Host -ForegroundColor Yellow ">>>> Houseking Workspace"
 Remove-Item -Path $PKGPATH
 Write-Host " "
 Write-Host -ForegroundColor Yellow ">>>> Done"
 Write-Host " "

Step-05b – Jenkins – Build Step – Bash Script – If Jenkins Host is based of *nix

 AEMPORT=4502
 CQ_USER=admin
 HOSTNAMED=192.168.2.8
 CQ_PASSD=admin
 HOSTNAMEI=192.168.2.8
 CQ_PASSI=admin
 PKGNAME=aemgit.ui.apps-1.0-SNAPSHOT.zip
 PKGPATH=./"${PKGNAME}"
 ICURL=http://${HOSTNAMEI}:${AEMPORT}/crx/packmgr/service.jsp
 DCURL=http://${HOSTNAMED}:${AEMPORT}/etc/packages/aemgit/${PKGNAME}
 RCURL="http://${HOSTNAMEI}:${AEMPORT}/crx/packmgr/service/script.html/etc/packages/aemdev/${PKGNAME}?cmd=replicate"

 echo " "
 echo  ">>>> Downloading APPS Package"
 curl -u ${CQ_USER}:${CQ_PASSD} ${DCURL} --output ${PKGPATH}
 echo " "
 echo ">>>> Package Downlaod Complete"

 echo " "
 echo  ">>>> Uploading and installing Package"
 curl -u ${CQ_USER}:${CQ_PASSI} -F "file=@${PKGPATH}" -F name='AEM_GIT_APP' -F force=true -F install=true ${ICURL}
 echo " "
 echo ">>>> Installation Complete"

 echo " "
 echo  ">>>> Replicating package"
 curl -u "${CQ_USER}:${CQ_PASSI}" -X POST $RCURL
 echo " "
 echo  ">>>> Replication Complete"
 echo " " 

 echo " "
 echo  ">>>> Houseking Workspace"
 rm -rf  ${PKGPATH}
 echo " "
 echo  ">>>> Done"
 echo " "
 

Step-06: Final output

Screen Shot 2018-09-29 at 8.27.06 PM
AEM Package – Installed – On Author Instance
screen-shot-2018-09-29-at-8-28-49-pm.png
Jenkins Console — Output

Shashi View All

-== Superman ==-

One thought on “AEM — Download, Install & Replicate Package Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: