]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: add 'name' to local repo-obj, exit if branch is not found
authorMathias Klette <mathias.klette@profitbricks.com>
Wed, 5 Jun 2013 17:59:54 +0000 (19:59 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Wed, 5 Jun 2013 17:59:54 +0000 (19:59 +0200)
debian_build.py

index 174236b0d3c2c453d3ca11244a8e49dbcf84ba77..d5238e5a5ab03223974919c5c69ea88d0d48104f 100755 (executable)
@@ -121,15 +121,6 @@ if __name__ == '__main__':
 
     # .. repository related
     gitrepo = git.Repo('.')
-    local_branch = re.match('^(origin/)?(.*)', ENV['GIT_BRANCH']).groups()[1]
-    remote_branch = os.path.join('origin', local_branch)
-    curr_commit = gitrepo.commit(remote_branch)
-    # id attribute used in python-git 0.3.2~RC1-1 found in wheezy
-    if hasattr(curr_commit, 'hexsha'):
-        curr_commit_id = curr_commit.hexsha
-    # id attribute used in python-git 0.1.6-1 found in squeeze
-    elif hasattr(curr_commit, 'id'):
-        curr_commit_id = curr_commit.id
     # this should be part of 'git' lib, but it isn't right now
     gitrepo.remotes = {}
     for remote in gitrepo.git.remote('-v').split('\n'):
@@ -139,9 +130,29 @@ if __name__ == '__main__':
             gitrepo.remotes.update({name: {type: url}})
         else:
             gitrepo.remotes[name].update({type: url})
+    # this would also be helpful, but is not yet included in git lib
+    gitrepo.name = gitrepo.remotes['origin']['fetch'].split('/')[-1]
+    # some local variables
+    local_branch = re.match('^(origin/)?(.*)', ENV['GIT_BRANCH']).groups()[1]
+    remote_branch = os.path.join('origin', local_branch)
+    curr_commit = gitrepo.commit(remote_branch)
+    # id attribute used in python-git 0.3.2~RC1-1 found in wheezy
+    if hasattr(curr_commit, 'hexsha'):
+        curr_commit_id = curr_commit.hexsha
+    # id attribute used in python-git 0.1.6-1 found in squeeze
+    elif hasattr(curr_commit, 'id'):
+        curr_commit_id = curr_commit.id
+
 
     # Act II: make decissions
     # compatibility until call_jenkins was replaced
+    if ENV['GIT_BRANCH'] not in [branch.name for branch in gitrepo.branches]:
+        logger.error('No branch {branch} found in {name}'.format(
+            branch=ENV['GIT_BRANCH'],
+            name=gitrepo.name,
+        ))
+        exit_error()
+
     if curr_dist not in ('squeeze', 'wheezy'):
         logger.warn('Compatibility Mode: Change distribution {old} => {new}.'.format(
             old=curr_dist,
@@ -163,7 +174,7 @@ if __name__ == '__main__':
         # replace valid debian version chars that are invalid for git tagging
         new_tag = curr_version.replace('~', '_').replace(':', ',')
         # .. only take care of changelog automation if we want it to
-        if gitrepo.remotes['origin']['fetch'].split('/')[-1] in AUTO_CHANGELOG_REPONAMES:
+        if gitrepo.name in AUTO_CHANGELOG_REPONAMES:
             do_autoincrement = True
         # reset actions
         if curr_dist == 'squeeze':
@@ -448,7 +459,7 @@ if __name__ == '__main__':
       {command}
 
 '''.format(
-            code=ret
+            code=ret,
             hostname=socket.gethostname(),
             jenkins_user=ENV['USER'],
             jenkins_workspace=ENV['WORKSPACE'],