Wednesday, July 3, 2024

Automating AEM Deployment with Jenkins

 Automating AEM Deployment with Jenkins






Automating the deployment process of Adobe Experience Manager (AEM) can significantly enhance your development workflow. In this blog post, we'll guide you through setting up a Jenkins pipeline for deploying AEM packages. This includes fetching code from BitBucket, building it with Maven, and deploying to AEM instances.

Prerequisites

Before starting, ensure you have the following:

  • Jenkins installed and configured.
  • Maven installed on your Jenkins server.
  • Credentials for your BitBucket repository.
  • AEM instances (Author, Publish, Dispatcher) up and running.


  • Jenkins Pipeline Script

    Here is a step-by-step Jenkins pipeline script for AEM deployment:

    Setting Up the Environment

    We define essential environment variables for AEM instances and user credentials.

    pipeline {
        agent any
        environment {
            AUTHOR_01 = "Author URL"
            PUBLISH_01 = "Publish URL"
            DISPATCHER_01 = "Dispatcher URL"
            PORT = "your port"
            PROTOCOL = "https/http"
            CONSOLE_USER = "username"
            CONSOLE_PASSWORD = "password"
        }
        tools {
            maven 'maven3'
        }

    Fetching Code from BitBucket

    In this stage, we clone the code from the specified branch in BitBucket.

        stages {
            stage('Get Code from BitBucket') {
                steps {
                    git branch: 'branch name', credentialsId: 'Credential ID', url: 'repo URL'
                }
            }


    Building the Project

    Next, we build the project using Maven. We use a Maven settings file to configure the build.

            stage('Build') {

                steps {

                    configFileProvider([configFile(fileId: '[file ID]', variable: 'MAVEN_SETTINGS')]) {

                        sh 'mvn -s $MAVEN_SETTINGS clean install'

                    }

            }

    }


    Deployment to AEM

    We deploy the built packages to both the Author and Publish instances in parallel.

            stage('Deployment') {

                parallel {

                    stage('Author') {

                        steps {

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectName.ui.apps-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectName.ui.config-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.config-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles/projectName.core --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectName.ui.content-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.content-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectName.all-1.0-SNAPSHOT.zip ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.all-1.0-SNAPSHOT.zip --insecure'

                        }

                    }

                    stage('Publisher') {

                        steps {

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectName.ui.apps-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectName.ui.config-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.config-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles/projectName.core --insecure'


                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectName.ui.content-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.ui.content-1.0-SNAPSHOT.zip --insecure'

                            

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectName.all-1.0-SNAPSHOT.zip ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                            sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectName.all-1.0-SNAPSHOT.zip --insecure'

                        }

                    }

                }

            }

        }

        post {

            always {

                emailext to: "email address",

                subject: "<email title>",

                body: "<email body>"

            }

        }

    }

    All Script in Once

    pipeline {

        agent any

        environment {

            AUTHOR_01="Author URL"

            PUBLISH_01="Publish URL"

            DISPATCHER_01="Dispatcher URL"

            PORT="your port"

            PROTPOCOL="https/http"

            CONSOLE_USER="username"

            CONSOLE_PASSWORD="password"

            

        }

        tools {

            maven 'maven3' 

        }

        stages {

            stage('Get Code from BitBucket') {

                steps {

                    git branch: 'branch name', credentialsId: 'Credential ID', url: 'repo URL'

                }

            }

            

            stage('Build'){

                steps {

                    configFileProvider(

                        [configFile(fileId: '[file ID]', variable: 'MAVEN_SETTINGS')]) {

                            sh 'mvn -s $MAVEN_SETTINGS clean install'

                    }

                }

                

            }

            

            stage('Deployment') {

                    parallel {

                        stage('Author') {

                            steps {

                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectnName.ui.apps-1.0-SNAPSHOT.zip ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectnName.ui.config-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.config-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectnName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectnName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTPOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/system/console/bundles/projectnName.core --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectnName.ui.content-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.content-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectnName.all-1.0-SNAPSHOT.zip ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${AUTHOR_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.all-1.0-SNAPSHOT.zip --insecure'


                            }

                        }

                        stage('Publisher') {

                            steps {

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.apps-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.apps/target/projectnName.ui.apps-1.0-SNAPSHOT.zip ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.apps-1.0-SNAPSHOT.zip --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.config-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.config/target/projectnName.ui.config-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.config-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=install -F name=projectnName.core-1.0-SNAPSHOT.jar -F force=true -F bundlefile=@./core/target/projectnName.core-1.0-SNAPSHOT.jar -F bundlestartlevel=20 ${PROTPOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F action=start -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/system/console/bundles/projectnName.core --insecure'


                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.ui.content-1.0-SNAPSHOT.zip -F force=true -F file=@./ui.content/target/projectnName.ui.content-1.0-SNAPSHOT.zip  ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.ui.content-1.0-SNAPSHOT.zip --insecure'

                                

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F name=projectnName.all-1.0-SNAPSHOT.zip -F force=true -F file=@./all/target/projectnName.all-1.0-SNAPSHOT.zip ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service.jsp --insecure'

                                sh 'curl -u ${CONSOLE_USER}:${CONSOLE_PASSWORD} -F cmd=install -F force=true ${PROTPOCOL}://${PUBLISH_01}:${PORT}/crx/packmgr/service/.json/etc/packages/sa.com.stc/projectnName.all-1.0-SNAPSHOT.zip --insecure'


                            }

                        }

                        

                    }

                }

            

        }

        post{

            always{

                emailext to: "email address",

                subject: "<email title>",

                body: "<email body>"

           }

        }


    }

    Conclusion

    By automating the deployment of AEM packages using Jenkins, you can streamline your workflow, reduce manual errors, and ensure a consistent deployment process. This script covers essential stages such as fetching code, building the project, and deploying it to AEM instances.



    Previous Post
    Next Post

    post written by:

    0 comments: