Add package lists to job logs 21/11121/3
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Thu, 7 Jun 2018 21:35:02 +0000 (14:35 -0700)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Fri, 8 Jun 2018 19:26:01 +0000 (12:26 -0700)
A listing of packages that are on the system is useful for debugging
changes that happen during a job run

Issue: RELENG-798
Change-Id: I88bc2eca175bbef1b7581b26199aff9a13f1910d
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
jenkins-init-scripts/init.sh
jenkins-init-scripts/package-listing.sh [new file with mode: 0755]
jjb/lf-macros.yaml
shell/package-listing.sh [new file with mode: 0644]

index ba5cb2a..3ddcc6f 100755 (executable)
@@ -11,6 +11,7 @@
 
 INIT_SCRIPTS_DIR="/opt/ciman/jjb/global-jjb/jenkins-init-scripts"
 
+"$INIT_SCRIPTS_DIR/package-listing.sh"
 "$INIT_SCRIPTS_DIR/basic-settings.sh"
 "$INIT_SCRIPTS_DIR/disable-firewall.sh"
 "$INIT_SCRIPTS_DIR/create-swap-file.sh"
diff --git a/jenkins-init-scripts/package-listing.sh b/jenkins-init-scripts/package-listing.sh
new file mode 100755 (executable)
index 0000000..2598a22
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# Share script with JJB jobs so we only have to maintain it in one place
+JJB_SHELL_DIR="$(dirname $0)/../shell"
+
+# Make sure the script is executable and then run it
+chmod +x "${JJB_SHELL_DIR}/package-listing.sh"
+"${JJB_SHELL_DIR}/package-listing.sh"
index ba419c6..e908282 100644 (file)
       - description-setter:
           regexp: '^Build logs: .*'
 
+- builder:
+    name: lf-infra-package-listing
+    builders:
+      - shell: !include-raw:
+          - ../shell/package-listing.sh
+
 - builder:
     name: lf-infra-packer-build
     builders:
                 - UNSTABLE
               build-steps:
                 - lf-infra-sysstat
+                - lf-infra-package-listing
                 - lf-infra-ship-logs
           mark-unstable-if-failed: true
       - workspace-cleanup:
diff --git a/shell/package-listing.sh b/shell/package-listing.sh
new file mode 100644 (file)
index 0000000..0c35917
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+echo "---> package-listing.sh"
+
+# Ensure we fail the job if any steps fail
+set -eu -o pipefail
+
+set -x # Trace commands for this script to make debugging easier
+
+OS_FAMILY=$(facter osfamily | tr '[:upper:]' '[:lower:]')
+
+START_PACKAGES=/tmp/packages_start.txt
+END_PACKAGES=/tmp/packages_end.txt
+DIFF_PACKAGES=/tmp/packages_diff.txt
+
+# This script may be run during system boot, if that is true then there will be
+# a starting_packages file. We will want to create a diff if we have a starting
+# packages file
+PACKAGES="${START_PACKAGES}"
+if [ -f "${PACKAGES}" ]
+then
+    PACKAGES="${END_PACKAGES}"
+    CREATEDIFF=1
+fi
+
+case "${OS_FAMILY}" in
+    redhat|suse)
+        # RedHat and Suse flavors all use rpm at the package level
+        rpm -qa | sort > "${PACKAGES}"
+    ;;
+    debian)
+        # Debian derived flavors all use dpkg at the package level
+        dpkg -l | grep '^ii' > "${PACKAGES}"
+    ;;
+    *)
+        # nothing to do
+    ;;
+esac
+
+if [ "${CREATEDIFF}" ]
+then
+    diff "${START_PACKAGES}" "${END_PACKAGES}" > "${DIFF_PACKAGES}"
+fi
+
+# If running in a Jenkins job, then copy the created files to the archives
+# location
+if [ "${WORKSPACE}" ]
+then
+    mkdir -p "${WORKSPACE}/archives/"
+    cp -f /tmp/packages_*.txt "${WORKSPACE}/archives/"
+fi