git 远程自动打tag

rm -rf *
git reset --hard && git clean -fdx

#git init
git config --global http.sslVerify false 
#对IFS变量 进行替换处理
OLD_IFS="$IFS"
IFS="@"
array=($gitUrl)
IFS="$OLD_IFS"
for i in ${array[*]};do
	gitUrl=$i
done
echo $gitUrl
git config http.postBuffer 524288000
gitUrl=${gitUrl/://} git clone -b $branch https://$username:$password@$gitUrl #以git开头的url,截取@符号后面的内容,:替换成/ git tag -d $tagName || git push $branch :refs/tags/$tagName || echo "清理tag" #创建tag git tag -a $tagName -m "$comment" sshpass -p $password git push $branch ${tagName}

  

    • expect远程提交tag
      #提交tag
      
      dateTime=`date -d "now" +%Y%m%d`
      tagName="RT-V2.0.$version.$dateTime"
      git tag -a $tagName -m "$comment"
      
      
      /usr/bin/expect<<EOF
      set timeout 30
      spawn git push origin ${tagName}
      expect { 
      "Username for 'https://git.uyunsoft.cn':" {  send "$username\r" }
      "Password for 'https://$username@git.uyunsoft.cn':" { send "$password\r" }
      }
      expect "Password for 'https://$username@git.uyunsoft.cn':" { send "$password\r" }
      expect eof
      EOF
      

        最终最完善版本,gitUrl必须是https开头的那个地址,不是git开头的地址

      rm -rf *
      rm -rf .git
      git reset --hard && git clean -fdx

      git init
      git config --global http.sslVerify false

      git config http.postBuffer 524288000


      #branch=${branch##*/}
      branch=${branch#origin/}

      gitUrl_real=$gitUrl
      gitUrl=${gitUrl##*:}
      gitUrl=`echo ${gitUrl:2}`
      gitUrl="https://$username:$password@$gitUrl"

      git remote add $branch $gitUrl
      dateTime=`date -d "now" +%Y%m%d`
      tagName="RT-V2.0.$version.$dateTime"
      git tag -d $tagName ||

      git push $branch :refs/tags/$tagName ||
      echo "清理指定分支的tag"

      #创建tag

      git fetch --tags --progress --quiet -- $gitUrl +refs/heads/*:refs/remotes/origin/* 2>&1

      remote_branch=`git branch -r|grep "origin/$branch$"`
      echo $remote_branch
      #if [ $remote_branch == "" ];then
      #remote_branch=`git branch -r|grep "$branch$"`
      #endif
      head=`git rev-parse $remote_branch`

      git checkout -f $head
      git branch -a -v --no-abbrev
      git checkout -b $branch $head


      git tag -a $tagName -m "$comment"
      sshpass -p $password git push $branch ${tagName}

        python版代码,增加了报错邮件发送和错误校验

      11
      

        

原文地址:https://www.cnblogs.com/slqt/p/13602227.html