Fix the documentation-* jobs, and add SSH publisher

Change-Id: Ie28cf03be5ad62d49c80e4c83b4d58a97226c4af
diff --git a/jjb/api-test.yaml b/jjb/api-test.yaml
index f024b31..3369ad5 100644
--- a/jjb/api-test.yaml
+++ b/jjb/api-test.yaml
@@ -13,6 +13,7 @@
           gerrit-server-name: '{gerrit-server-name}'
           project-regexp: '^{project}$'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{all-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
@@ -31,7 +32,7 @@
 
     # Run the master branch Jenkinsfile from cord-tester against all other revisions
     pipeline-scm:
-      script-path: 'Jenkinsfile/verify-api-test-JenkinsFile'
+      script-path: 'Jenkinsfile/verify-api-tests-JenkinsFile'
       scm:
         - git:
            url: '{gerrit-server-url}/cord-tester'
diff --git a/jjb/cord-macros.yaml b/jjb/cord-macros.yaml
index c4709dd..8e43216 100644
--- a/jjb/cord-macros.yaml
+++ b/jjb/cord-macros.yaml
@@ -15,20 +15,21 @@
     name: cord-infra-gerrit-repo-scm
     scm:
       - repo:
-          manifest-url: '{gerrit-server-url}'
+          manifest-url: '{manifest-url}'
           manifest-branch: '{branch}'
           destination-dir: '{destination-dir}'
           jobs: 4
           reset-first: true
           depth: 1
 
-# download a specific patchset after checking out enitre source tree with repo
+# download a specific patchset after checking out entire source tree with repo
 # docs: https://docs.openstack.org/infra/jenkins-job-builder/builders.html#builders.inject
 - builder:
     name: cord-infra-gerrit-repo-patch
     builders:
       - inject:
           properties-content: |
+            DESTINATION_DIR={destination-dir}
             GERRIT_PROJECT={project}
             GERRIT_CHANGE_NUMBER={change-number}
             GERRIT_PATCHSET_NUMBER={patchset-number}
@@ -57,6 +58,9 @@
               branches:
                 - branch-compare-type: REG_EXP
                   branch-pattern: '{branch-regexp}'
+              file-paths:
+                - compare-type: REG_EXP
+                  pattern: '{file-include-regexp}'
 
 # trigger on gerrit commits/merges
 - trigger:
@@ -74,3 +78,6 @@
               branches:
                 - branch-compare-type: REG_EXP
                   branch-pattern: '{branch-regexp}'
+              file-paths:
+                - compare-type: REG_EXP
+                  pattern: '{file-include-regexp}'
diff --git a/jjb/defaults.yaml b/jjb/defaults.yaml
index e9bb2f0..5ca5ae9 100644
--- a/jjb/defaults.yaml
+++ b/jjb/defaults.yaml
@@ -32,12 +32,16 @@
     gerrit-server-name: 'CORD Gerrit'
 
     # URL for Gerrit server, for use with `repo`
-    gerrit-server-url: 'https://gerrit.opencord.org/'
+    gerrit-server-url: 'https://gerrit.opencord.org'
 
     # name of the manifest git repos used with the `repo` cli tool
     cord-repo-manifest: manifest.git
     cordqa-manifest-repo: qa-manifest.git
 
-    # list of supported branch as a regexp
+    # regexp for gerrit triggers
+    # list of supported branches, for branch-regexp
     supported-branches-regexp: '^(master|cord-5.0|cord-4.1|cord-4.0)$'
 
+    # for matching files with file-include-regexp
+    all-files-regexp: '.*'
+    doc-files-regexp: "^docs/.*"
diff --git a/jjb/docs.yaml b/jjb/docs.yaml
index 1cc480f..39477a6 100644
--- a/jjb/docs.yaml
+++ b/jjb/docs.yaml
@@ -20,13 +20,15 @@
 
 # Documentation job templates
 - job-template:
+    id: verify-documentation
     name: "verify-documentation"
 
     triggers:
       - cord-infra-gerrit-trigger-patchset:
           gerrit-server-name: '{gerrit-server-name}'
-          project-regexp: '$GERRIT_PROJECT'
+          project-regexp: '{project-regexp}'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{doc-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
@@ -41,7 +43,7 @@
 
     scm:
       - cord-infra-gerrit-repo-scm:
-          gerrit-server-url: '{gerrit-server-url}'
+          manifest-url: '{gerrit-server-url}/{cord-repo-manifest}'
           branch: '$GERRIT_BRANCH'
           destination-dir: 'cord'
 
@@ -51,6 +53,7 @@
 
     builders:
       - cord-infra-gerrit-repo-patch:
+          destination-dir: 'cord'
           project: '$GERRIT_PROJECT'
           change-number: '$GERRIT_CHANGE_NUMBER'
           patchset-number: '$GERRIT_PATCHSET_NUMBER'
@@ -58,8 +61,8 @@
           cd cord/build/docs
           make test
 
-
 - job-template:
+    id: publish-documentation
     name: 'publish-documentation'
 
     triggers:
@@ -67,6 +70,7 @@
           gerrit-server-name: '{gerrit-server-name}'
           project-regexp: '{project-regexp}'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{doc-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
@@ -81,7 +85,7 @@
 
     scm:
       - cord-infra-gerrit-repo-scm:
-          gerrit-server-url: '{gerrit-server-url}'
+          manifest-url: '{gerrit-server-url}/{cord-repo-manifest}'
           branch: '$GERRIT_BRANCH'
           destination-dir: 'cord'
 
@@ -95,6 +99,15 @@
           make build
 
 # publish over ssh: https://docs.openstack.org/infra/jenkins-job-builder/publishers.html#publishers.ssh
-#    publishers:
-#     - ssh:
+    publishers:
+      - ssh:
+          site: 'CORD Wiki'
+          source: 'cord/build/docs/_book/**'
+          remove-prefix: 'cord/build/docs/_book'
+          target: '//var/www/guide/$GERRIT_BRANCH'
+      - ssh:
+          site: 'CORD Wiki'
+          source: 'cord/build/docs/xos/swagger/**'
+          remove-prefix: 'cord/build/docs/xos'
+          target: '//var/www/guide/$GERRIT_BRANCH'
 
diff --git a/jjb/lint.yaml b/jjb/lint.yaml
index e08f8e6..171c469 100644
--- a/jjb/lint.yaml
+++ b/jjb/lint.yaml
@@ -15,6 +15,7 @@
           gerrit-server-name: '{gerrit-server-name}'
           project-regexp: '^{project}$'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{all-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
@@ -57,6 +58,7 @@
           gerrit-server-name: '{gerrit-server-name}'
           project-regexp: '^{project}$'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{all-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
@@ -99,6 +101,7 @@
           gerrit-server-name: '{gerrit-server-name}'
           project-regexp: '^{project}$'
           branch-regexp: '{branch-regexp}'
+          file-include-regexp: '{all-files-regexp}'
           dependency-jobs: '{dependency-jobs}'
 
     properties:
diff --git a/jjb/shell/repopatch.sh b/jjb/shell/repopatch.sh
index 93c9706..4e38e66 100644
--- a/jjb/shell/repopatch.sh
+++ b/jjb/shell/repopatch.sh
@@ -17,17 +17,23 @@
 # repopatch.sh
 # downloads a patch to within an already checked out repo tree
 
-set +e -u -o pipefail
+set -eu -o pipefail
 
 # verify that we have repo installed
 command -v repo >/dev/null 2>&1 || { echo "repo not found, please install it" >&2; exit 1; }
 
-echo "Checking out patch with repo, using repo version:"
-repo version
-
+echo "DESTINATION_DIR: ${DESTINATION_DIR}"
 echo "GERRIT_PROJECT: ${GERRIT_PROJECT}"
 echo "GERRIT_CHANGE_NUMBER: ${GERRIT_CHANGE_NUMBER}"
 echo "GERRIT_PATCHSET_NUMBER: ${GERRIT_PATCHSET_NUMBER}"
 
-echo "Make this work eventually!"
+pushd "${DESTINATION_DIR}"
+echo "Checking out a patchset with repo, using repo version:"
+repo version
+
+PROJECT_PATH=$(xmllint --xpath "string(//project[@name=\"${GERRIT_PROJECT}\"]/@path)" .repo/manifest.xml)
+echo "Project Path: $PROJECT_PATH"
+
+repo download "${PROJECT_PATH}" "$GERRIT_CHANGE_NUMBER/${GERRIT_PATCHSET_NUMBER}"
+popd