#!/bin/bash
-set -o errexit
+# SPDX-license-identifier: Apache-2.0
set -o pipefail
export PATH=$PATH:/usr/local/bin/
+EXITSTATUS=0
-# If no violations were found, no lint log will exist.
+# This Log should always exist
if [[ -e securityaudit.log ]] ; then
- echo -e "\nposting security audit report to gerrit...\n"
- cat securityaudit.log | awk -F"ERROR\ \-\ " '{print $2}' > shortlog
+ #check if log has errors
+ if grep ERROR securityaudit.log; then
+ EXITSTATUS=1
+ fi
- ssh -p 29418 gerrit.opnfv.org \
- "gerrit review -p $GERRIT_PROJECT \
- -m \"$(cat shortlog)\" \
- $GERRIT_PATCHSET_REVISION \
- --notify NONE"
+ grep 'ERROR' securityaudit.log | awk -F"ERROR - " '{ print $2 }' | tr -d "\'\"" > shortlog
- exit 1
+ # Only report to Gerrit when there are errors to report.
+ if [[ -s shortlog ]]; then
+ echo -e "\nposting security audit report to gerrit...\n"
+ ssh -p 29418 gerrit.opnfv.org \
+ "gerrit review -p $GERRIT_PROJECT \
+ -m \"$(cat shortlog)\" \
+ $GERRIT_PATCHSET_REVISION \
+ --notify NONE"
+ fi
+
+ exit $EXITSTATUS
fi