build腳本java
CE=$(git log -1 --pretty=format:"%ce") CN=$(git log -1 --pretty=format:"%cn") AR=$(git log -1 --pretty=format:"%ar") DATE=$(git log -1 --pretty=format:"%ad" --date=local) MSG=$(git log -1 --pretty=format:"%s") BRANCH_NAME=$(git branch|sed -n '1p;1q') git branch SUBJECT="SonarQube Analysis Result Of Your Latest Commit on Project yangyang(committed $AR:$MSG)" SHARE_DIR=/opt/share JENKINS_CLI=$SHARE_DIR/jenkins-cli.jar USERNAME=jenkins PASSWORD=admin #BODY=`java -jar $JENKINS_CLI -s $JENKINS_URL console ${JOB_NAME} $BUILD_ID --username $USERNAME --password $PASSWORD` HEADER="hello,$CN" #swaks --to $CE --from newtouchcloud@newtouch.com --server mail.newtouch.com --tlsc -au newtouchcloud@newtouch.com -ap p3Yy69dl6i --d "Date: %DATE%\nTo: %TO_ADDRESS%\nFrom: %FROM_ADDRESS%\nSubject: $SUBJECT\nX-Mailer: swaks v$p_version jetmore.org/john/code/swaks/\n%NEW_HEADERS%\n%BODY%\n" --body "$BODY" --header "$HEADER" TIMESTAMP=$(date +%Y%m%d-%H:%M:%S:%N) cd $SHARE_DIR/jenkins echo "JOBNAME=${JOB_NAME}" >> $TIMESTAMP.to-process echo "BUILDID=${BUILD_ID}" >> $TIMESTAMP.to-process echo "CE=${CE}" >> $TIMESTAMP.to-process echo "CN=${CN}" >> $TIMESTAMP.to-process echo "BRANCH_NAME=${BRANCH_NAME}" >> $TIMESTAMP.to-process echo "EMAIL_SUBJECT=${SUBJECT}" >> $TIMESTAMP.to-process echo "EMAIL_BODY=${BODY}" >> $TIMESTAMP.to-process echo "EMAIL_HEADER=${HEADER}" >> $TIMESTAMP.to-process echo "MSG=${MSG}" >> $TIMESTAMP.to-process echo "DATE=${DATE}" >> $TIMESTAMP.to-process
發送郵件的腳本git
cd /opt/share/jenkins PARSER=/opt/share/parser.sh #send_mail <filename> send_mail(){ CONF_FILE=$1 #RENAME FILE CONF_FILE_PROC=$(echo $CONF_FILE | cut -d "." -f 1).processing mv $CONF_FILE $CONF_FILE_PROC CONF_FILE=$CONF_FILE_PROC CE=$($PARSER CE $CONF_FILE) CN=$($PARSER CN $CONF_FILE) BRANCH_NAME=$($PARSER CE $CONF_FILE) SUBJECT=$($PARSER EMAIL_SUBJECT $CONF_FILE) HEADER=$($PARSER EMAIL_HEADER $CONF_FILE) TARGET_JOB_NAME=$($PARSER JOBNAME $CONF_FILE) TARGET_BUILD_ID=$($PARSER BUILDID $CONF_FILE) JENKINS_CLI=/opt/share/jenkins-cli.jar USERNAME=jenkins PASSWORD=admin BODY=`java -jar $JENKINS_CLI -s $JENKINS_URL console ${TARGET_JOB_NAME} $TARGET_BUILD_ID --username $USERNAME --password $PASSWORD | grep -a 'INFO: ANALYSIS SUCCESSFUL'` #BODY=hello swaks --to $CE --from newtouchcloud@newtouch.com --server mail.newtouch.com --tlsc -au newtouchcloud@newtouch.com -ap p3Yy69dl6i --d "Date: %DATE%\nTo: %TO_ADDRESS%\nFrom: %FROM_ADDRESS%\nSubject: $SUBJECT\nX-Mailer: swaks v$p_version jetmore.org/john/code/swaks/\n%NEW_HEADERS%\n%BODY%\n" --body "$BODY" --header "$HEADER" mv $CONF_FILE $(echo $CONF_FILE | cut -d "." -f 1).processed #delete temp conf file rm $(echo $CONF_FILE | cut -d "." -f 1).processed } for file in $(ls) do if [ $(echo $file | cut -d "." -f 2) = 'to-process' ]; then send_mail $file fi done