Jenkins Configuration(4)Improve Shell Script Debug/Info Message

Jenkins Configuration(4)Improve Shell Script Debug/Info Message
Just take example from my colleagues' scripts. I found I can improve my shell script to give some debug or info messages.

Just take this test.sh as example:

#!/bin/sh

#Parameters

#define the log file directory
LOGFILE=/var/log/test.log
#debug flag
DEBUG=0
#info flag
INFO=1

#Functions

debug() {
if [ "$DEBUG" -gt 0 ] ; then
  NOW=$(date +"%m-%d-%Y %H:%M:%S")
  echo "DEBUG [$NOW] $1" | tee -a $LOGFILE
fi
}

info() {
if [ "$INFO" -gt 0 ] ; then
  NOW=$(date +"%m-%d-%Y %H:%M:%S")
  echo "INFO [$NOW] $1" | tee -a $LOGFILE
fi
}

info "Some information will echo here"

debug "Some debug information will echo here"


References:


你可能感兴趣的:(configuration)