一次github和jenkins集成构建异常处理

最近Jenkins出问题了,github总是behind Apache eagle 6个commits。下面是我们构建的shell

#!/bin/bash
unset SSH_ASKPASS
git checkout master
git status
echo "Git remote..."
git remote add upstream https://github.com/apache/eagle.git
git remote set-url origin "https://{username}:{token}@github.com/1haodian/eagle.git"
echo "Fetch..."
git fetch upstream
echo "Rebase..."
git rebase upstream/master 
echo "Pushing with force ..."
git push --force origin master > /dev/null 2>&1 || exit 1
echo "Pushed deployment successfully"
exit 0

检查token没问题,构建也不报错。只能去jenkins主机去查问题,在workspace下 git log,得知rebase执行成功,apache eagle最新的代码也在,只能说明最后一步push出问题了。直接执行push也不报错,但是很快执行结束。没辙。。。

git branch时发现,checkout依旧如此。

[chitin eaglemaster]$ git branch
* (no branch)
[chitin eaglemaster]$ git checkout master
Previous HEAD position was 1f16c58... Fix compile error introduced by EAGLE-993
HEAD is now at 26a2889... Fix compile error introduced by EAGLE-993
[chitin eaglemaster]$ git branch 

[chitin eaglemaster]$ git checkout -b master
Switched to a new branch 'master'
[chitin eaglemaster]$ git branch       `这里写代码片`              
* master
* (no branch)

上网查询发现需要执行git checkout -b master,果然可以,遂再次push

git push  origin master
error: src refspec master matches more than one.
error: failed to push some refs to 'https://{username}:{token}@github.com/1haodian/eagle.git'

再次请教白谷老师,大致意思是origin有“master”的branch和“master”的tag,注意这儿branch和tag同名,删除orgin上的“master” tag

[yhd@yhd-hk eaglemaster]$ git push origin --delete tag master
To https://{username}:{token}@github.com/1haodian/eagle.git
- [deleted] master

再次push成功

This branch is 66 commits ahead of apache:master.

记录下,防止下次遇到忘记。

你可能感兴趣的:(note)