+++ /dev/null
-#!/bin/bash
-#This script will delete all tags on abandoned commit
-
-set -x
-#Update one git project
-update-git-project()
-{
- pushd .
- PRJ_PATH=$1
- PRJ_FULL_NAME=$2
- PRJ_NAME=$(basename ${PRJ_FULL_NAME})
-
- if [ ! -d ${PRJ_PATH} ]; then
- mkdir ${PRJ_PATH} -p
- fi
- cd ${PRJ_PATH}
- retry_num=3
- while [ $retry_num -ne 0 ]
- do
- #try pull the change from git, if failed, delete local code and re-clone
- if [ -d ${PRJ_NAME} ]; then
- cd ${PRJ_NAME}
- git pull 2>&1
- if [ $? -ne 0 ]; then
- cd ${PRJ_PATH}
- rm -rf ${PRJ_PATH}/${PRJ_NAME}
- git clone ssh://${GERRIT_USERNAME}@${GERRIT_HOSTNAME}:${GERRIT_SSHPORT}/${PRJ_FULL_NAME}
- else
- popd
- return 0
- fi
- else
- git clone ssh://${GERRIT_USERNAME}@${GERRIT_HOSTNAME}:${GERRIT_SSHPORT}/${PRJ_FULL_NAME}
- fi
- if [ $? -eq 0 -a -d ${PRJ_NAME} ]; then
- popd
- return 0
- else
- let "retry_num=retry_num-1"
- if [ $retry_num -eq 0 ]; then
- popd
- return 1
- fi
- rm ${PRJ_PATH}/${PRJ_NAME} -rf
- fi
- done
-}
-
-#Prepare necessary variable
-export http_proxy=""
-LANG=c
-unset LC_ALL
-PROJECT=$(basename ${GERRIT_PROJECT})
-GERRIT_PATH=$(echo ${GERRIT_PROJECT} | sed "s/^\(.*\)${PROJECT}$/\1/g")
-JENKINS_HOME=$(cd ${WORKSPACE}/../../..; pwd)
-
-#Update gerrit project from remote
-if [ -d ${JENKINS_HOME}/git/${GERRIT_PROJECT} ]; then
- cp ${JENKINS_HOME}/git/${GERRIT_PROJECT} ${WORKSPACE} -rf
-fi
-update-git-project ${WORKSPACE} ${GERRIT_PROJECT}
-if [ $? -ne 0 ]; then
- exit 1
-fi
-cd ${WORKSPACE}/${PROJECT}
-
-#Get all patchset ID of this change
-ssh -p ${GERRIT_SSHPORT} ${GERRIT_USERNAME}@${GERRIT_HOSTNAME} gerrit query "change:${GERRIT_CHANGE_NUMBER}" --patch-sets | egrep " revision:" > ${WORKSPACE}/patchsetid
-
-#Delete all tags on all patchsets
-index=1
-num=$(echo "0"${GERRIT_CHANGE_NUMBER} | sed "s/^.*\(..\)$/\1/g")
-cat ${WORKSPACE}/patchsetid | while IFS= ; read line
-do
- commitid=$(echo ${line} | sed "s/^[[:space:]]*revision:[[:space:]]*\([0-9a-z]*\)$/\1/g")
- git fetch ssh://${GERRIT_USERNAME}@${GERRIT_HOSTNAME}:${GERRIT_SSHPORT}/${GERRIT_PROJECT} refs/changes/${num}/${GERRIT_CHANGE_NUMBER}/${index} -t
- git checkout FETCH_HEAD
- while [ true ]
- do
- tag=$(git describe --tags --exact-match ${commitid})
- if [ $? -ne 0 ]; then
- break
- fi
- git push origin :refs/tags/${tag} -f
- git tag -d ${tag}
- done
- let index=$index+1
-done
-
-rm ${WORKSPACE}/* -rf
-exit 0