[JAMES-3226] Automatically publish staging doc (#11)

This enables building and publishing the antora documentation
automatically when the build of the master branche of james-project is
green.

Co-authored-by: Jean Helou <jhe@codamens.fr>
diff --git a/Jenkinsfile b/Jenkinsfile
index 52ea02c..f7659e9 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -28,8 +28,12 @@
         label AGENT_LABEL
     }
 
+    triggers {
+        upstream(upstreamProjects: '../ApacheJames/master', threshold: hudson.model.Result.SUCCESS)
+    }
+
     environment {
-        CI=true
+        CI = true
     }
 
     tools {
@@ -88,17 +92,29 @@
         failure {
             echo "Failed "
             script {
-                emailext(
-                        subject: "[BUILD-UNSTABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
-                        body: """
-BUILD-UNSTABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
+                if (env.BRANCH_NAME == "live" || env.BRANCH_NAME == "staging") {
+                    emailext(
+                            subject: "[BUILD-UNSTABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
+                            body: """
+        BUILD-UNSTABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
 
-Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
-""",
-                        to: "server-dev@james.apache.org",
-                        recipientProviders: [[$class: 'DevelopersRecipientProvider']]
-                )
+        Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
+        """,
+                            recipientProviders: [[$class: 'DevelopersRecipientProvider']]
+                    )
+                } else {
+                    emailext(
+                            subject: "[BUILD-UNSTABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
+                            body: """
+        BUILD-UNSTABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
+
+        Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
+        """,
+                            recipientProviders: [[$class: 'RequesterRecipientProvider']]
+                    )
+                }
             }
+
         }
 
         // If this build didn't fail, but there were failing tests, send an email to the list.
@@ -110,17 +126,31 @@
         success {
             echo "Success "
             script {
-                if ((currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) {
-                    emailext (
-                            subject: "[BUILD-STABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
-                            body: """
-BUILD-STABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
+                if (env.BRANCH_NAME == "live" || env.BRANCH_NAME == "staging") {
 
-Is back to normal.
-""",
-                            to: "server-dev@james.apache.org",
-                            recipientProviders: [[$class: 'DevelopersRecipientProvider']]
-                    )
+                    if ((currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) {
+                        emailext(
+                                subject: "[BUILD-STABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
+                                body: """
+    BUILD-STABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
+
+    Is back to normal.
+    """,
+                                recipientProviders: [[$class: 'DevelopersRecipientProvider']]
+                        )
+                    }
+                } else {
+                    if ((currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) {
+                        emailext(
+                                subject: "[BUILD-STABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'",
+                                body: """
+    BUILD-STABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]':
+
+    Is back to normal.
+    """,
+                                recipientProviders: [[$class: 'RequesterRecipientProvider']]
+                        )
+                    }
                 }
             }
         }