From: Andrew Grimberg Date: Thu, 7 Jun 2018 21:35:02 +0000 (-0700) Subject: Add package lists to job logs X-Git-Tag: v0.21.0~16^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F11121%2F3;p=releng%2Fglobal-jjb.git Add package lists to job logs 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 --- diff --git a/jenkins-init-scripts/init.sh b/jenkins-init-scripts/init.sh index ba5cb2a5..3ddcc6fe 100755 --- a/jenkins-init-scripts/init.sh +++ b/jenkins-init-scripts/init.sh @@ -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 index 00000000..2598a224 --- /dev/null +++ b/jenkins-init-scripts/package-listing.sh @@ -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" diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index ba419c69..e908282c 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -52,6 +52,12 @@ - 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: @@ -427,6 +433,7 @@ - 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 index 00000000..0c35917e --- /dev/null +++ b/shell/package-listing.sh @@ -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