[Compass4nfv] collect the logs and upload to artifact 43/51343/5
authorwutianwei <wutianwei1@huawei.com>
Tue, 30 Jan 2018 08:11:29 +0000 (16:11 +0800)
committerwutianwei <wutianwei1@huawei.com>
Tue, 30 Jan 2018 09:21:33 +0000 (17:21 +0800)
JIRA: COMPASS-579
Add a job to collect log and upload. what the job do
1. run collect-log.sh to get log from rsyslog container
2. copy log.tar.gz from compass-tasks to jumphost
3. upload the log.tar.gz to artifact

Change-Id: Ic2244e33e7ae4b7aa71e15af741191c850982053
Signed-off-by: wutianwei <wutianwei1@huawei.com>
jjb/compass4nfv/compass-ci-jobs.yml
jjb/compass4nfv/compass-logs.sh [new file with mode: 0644]

index 0790b83..70296bd 100644 (file)
     jobs:
       - 'compass-{scenario}-{pod}-daily-{stream}'
       - 'compass-deploy-{pod}-daily-{stream}'
+      - 'compass-collect-logs-{pod}-daily-{stream}'
 
 ########################
 # job templates
                     build-step-failure-threshold: 'never'
                     failure-threshold: 'never'
                     unstable-threshold: 'FAILURE'
+      - conditional-step:
+          condition-kind: and
+          condition-operands:
+            - condition-kind: regex-match
+              regex: master
+              label: '{stream}'
+          steps:
+            - trigger-builds:
+                - project: 'compass-collect-logs-{pod}-daily-{stream}'
+                  current-parameters: false
+                  predefined-parameters:
+                    DEPLOY_SCENARIO={scenario}
+                  block: true
+                  same-node: true
+                  block-thresholds:
+                    build-step-failure-threshold: 'never'
+                    failure-threshold: 'never'
+                    unstable-threshold: 'FAILURE'
+
 
 - job-template:
     name: 'compass-deploy-{pod}-daily-{stream}'
             - shell:
                 !include-raw-escape: ./compass-deploy.sh
 
+- job-template:
+    name: 'compass-collect-logs-{pod}-daily-{stream}'
+
+    disabled: '{obj:disabled}'
+
+    concurrent: true
+
+    properties:
+      - logrotate-default
+
+    parameters:
+      - project-parameter:
+          project: '{project}'
+          branch: '{branch}'
+      - compass-ci-parameter:
+          installer: '{installer}'
+          gs-pathname: '{gs-pathname}'
+          ppa-pathname: '{ppa-pathname}'
+      - '{slave-label}-defaults'
+      - '{installer}-defaults'
+
+    scm:
+      - git-scm
+
+    wrappers:
+      - build-name:
+          name: '$BUILD_NUMBER - Scenario: $DEPLOY_SCENARIO'
+      - fix-workspace-permissions
+
+    builders:
+      - description-setter:
+          description: "Built on $NODE_NAME"
+      - shell:
+          !include-raw-escape: ./compass-logs.sh
+
 ########################
 # parameter macros
 ########################
       - string:
           name: PPA_CACHE
           default: "$WORKSPACE/work/repo/"
+      - string:
+          name: LOG_DIRECTORY
+          default: $WORKSPACE/log_output
+          description: "Directory where the logs will be located upon the completion of the collection."
 
 ########################
 # trigger macros
diff --git a/jjb/compass4nfv/compass-logs.sh b/jjb/compass4nfv/compass-logs.sh
new file mode 100644 (file)
index 0000000..03c8b20
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -o nounset
+set -o pipefail
+
+# log info to console
+echo "Uploading the logs $INSTALLER_TYPE artifact. This could take some time..."
+echo "--------------------------------------------------------"
+echo
+
+# create the log directory if it doesn't exist
+[[ -d $LOG_DIRECTORY ]] || mkdir -p $LOG_DIRECTORY
+
+OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
+COMPASS_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}_${OPNFV_ARTIFACT_VERSION}.log.tar.gz"
+
+
+sudo docker exec -it compass-tasks /bin/bash /opt/collect-log.sh
+sudo docker cp compass-tasks:/opt/log.tar.gz ${LOG_DIRECTORY}/${COMPASS_LOG_FILENAME}
+
+sudo chown $(whoami):$(whoami) ${LOG_DIRECTORY}/${COMPASS_LOG_FILENAME}
+
+gsutil cp "${LOG_DIRECTORY}/${COMPASS_LOG_FILENAME}" \
+     "gs://${GS_URL}/logs/${COMPASS_LOG_FILENAME}" > /dev/null 2>&1
+
+echo
+echo "--------------------------------------------------------"
+echo "Done!"
+echo "Artifact is available as http://${GS_URL}/logs/${COMPASS_LOG_FILENAME}"