TPE-202 Retry git checkout if failed in submit job 72/145072/2
authorhyokeun <hyokeun.jeon@samsung.com>
Mon, 21 Aug 2017 06:30:35 +0000 (15:30 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Mon, 21 Aug 2017 07:28:49 +0000 (16:28 +0900)
Change-Id: I839a4d0210849d0ab5bf8be1b79d40fa9bcbc16e

job_submit.py

index 9be7a47..e701ce0 100644 (file)
@@ -27,6 +27,7 @@ import json
 import base64
 import re
 import ast
+import shutil
 import xml.etree.cElementTree as ElementTree
 from xml.sax.saxutils import escape
 from time import sleep
@@ -312,6 +313,23 @@ def main(build_type, build, event, sr_count):
         return 1
     mygit = Git(prjdir)
 
+    tag = find_submit_tag(event, mygit)
+    if not tag:
+        print '\nThis commit don\'t contain submit/*/* tag, exit now'
+        return 0
+
+    # checkout submit tag
+    try:
+        mygit.checkout(tag)
+    except Exception as err:
+        print 'Retrying git cloning due to checkout failure. %s' % repr(err)
+        shutil.rmtree(prjdir)
+        if not clone_gitproject(event['project'], prjdir):
+            print >> sys.stderr, 'Error cloning %s' % event['project']
+            return 1
+        mygit = Git(prjdir)
+        mygit.checkout(tag)
+
     # check whether tag name is start with 'submit/'
     if not event['refname'].startswith('refs/tags/submit/'):
         print '\nREFNAME "%s" isn\'t start with refs/tags/submit, exit now'\
@@ -331,11 +349,6 @@ def main(build_type, build, event, sr_count):
     mygerrit = Gerrit(event['hostname'], event['username'], \
             event['sshport'], int(os.getenv('GERRIT_SILENT_MODE')))
 
-    tag = find_submit_tag(event, mygit)
-    if not tag:
-        print '\nThis commit don\'t contain submit/*/* tag, exit now'
-        return 0
-
     result_str, cd_err, cd_ret = mygit._git_inout('for-each-ref', ['--format=%(tagger)', event['refname']])
     lparen = result_str.find('<')
     rparen = result_str.find('>')
@@ -363,9 +376,6 @@ def main(build_type, build, event, sr_count):
     packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
     print 'packaging dir is %s/%s' % (prjdir, packagingdir)
 
-    # checkout submit tag
-    mygit.checkout(tag)
-
     tagger = mygit.get_tag(tag)
 
     # get project mappings from git-obs-mapping and git-ref-mapping