]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: python-git needs special treatment
authorMathias Klette <mathias.klette@profitbricks.com>
Wed, 22 May 2013 16:29:52 +0000 (18:29 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Wed, 22 May 2013 16:29:52 +0000 (18:29 +0200)
Available in
  wheezy:  git.Repo('.').commit(<COMMIT_ID>).hexsha
  squeeze: git.Repo('.').commit(<COMMIT_ID>).id

debian_build.py

index 839183871364ed0380b0112083f324f0272b4b45..13516fb9de7966c3e870e36f829d22b8857b2065 100755 (executable)
@@ -131,11 +131,17 @@ if __name__ == '__main__':
     daily_date = BUILD_START.strftime('%Y%m%d%H%M%S')
 
     # .. repository related
-    gitrepo = git.Repo('.')
-    curr_commit = gitrepo.commit(ENV['GIT_COMMIT'])
     local_branch = re.match('^(origin/)?(.*)',ENV['GIT_BRANCH']).groups()[1]
     remote_branch = os.path.join('origin', local_branch)
     reports_file = os.path.join(ENV['WORKSPACE'], '../build-area/result/reports.tgz',)
+    gitrepo = git.Repo('.')
+    curr_commit = gitrepo.commit(ENV['GIT_COMMIT'])
+    # used in python-git 0.3.2~RC1-1 found in wheezy
+    if hasattr(curr_commit, 'hexsha'):
+        curr_commit_id = curr_commit.hexsha
+    # used in python-git 0.1.6-1 found in squeeze
+    elif hasattr(curr_commit, 'id'):
+        curr_commit_id = curr_commit.id
 
     # .. dput related (some overrides happening below, though)
     dput_obj = dput.Dput(
@@ -174,7 +180,7 @@ if __name__ == '__main__':
             #    except, the existing tag uses the same commit as we were triggered with
             remote_tag = [tag for tag in gitrepo.tags if tag.name == new_tag]
             if len(remote_tag) > 0:
-                if remote_tag[0].commit.id == curr_commit.hexsha:
+                if remote_tag[0].commit.id == curr_commit_id:
                     logger.debug('Tag was already created for this commit.')
                     do_tagging = False
                 else:
@@ -195,7 +201,7 @@ if __name__ == '__main__':
             version = curr_version,
             date = daily_date,
             build = ENV['BUILD_NUMBER'],
-            commit = curr_commit[0:7],
+            commit = curr_commit_id[0:7],
             )
         pb_suite = 'develop-' + ENV['DISTRIBUTION']
         # reset actions
@@ -213,7 +219,7 @@ if __name__ == '__main__':
             version = curr_version,
             date = daily_date,
             build = ENV['BUILD_NUMBER'],
-            commit = curr_commit.hexsha[0:7],
+            commit = curr_commit_id[0:7],
             )
         pb_suite = 'experimental-' + ENV['DISTRIBUTION']
         dput_obj.contents.update({
@@ -246,12 +252,12 @@ if __name__ == '__main__':
     #FIXME: get rid of jenkins parameter, instead use git remote
     #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
     #    if ENV['GIT_BRANCH_NAME'] == 'pre-staging':
-    #        version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit.hexsha[0:7])
+    #        version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit_id[0:7])
     #        changelog_distro = 'pre-staging'
     #    else:
     #        # use shorter date because we can
     #        daily_date = datetime.datetime.now().strftime('%Y%m%d')
-    #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit.hexsha[0:7])
+    #        version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit_id[0:7])
     #        changelog_distro = 'unstable'
 
     logger.debug('Distribution: "%s" => "%s"' %(curr_dist,new_dist))
@@ -336,7 +342,7 @@ if __name__ == '__main__':
             '--no-auto-nmu',
             '--',
             'Generated by Jenkins build of commit {commit}'.format(
-                commit = curr_commit.hexsha[0:7]
+                commit = curr_commit_id[0:7]
                 ),
             ]
 
@@ -381,7 +387,7 @@ if __name__ == '__main__':
         dist = ENV['DISTRIBUTION'],
         arch = 'amd64',
         pb_suite = pb_suite,
-        git_commit_id = curr_commit.hexsha[0:7]
+        git_commit_id = curr_commit_id[0:7]
         )
     ret = gbp.build()