]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: fix variable usage and usage of check_call-method
authorMathias Klette <mathias.klette@profitbricks.com>
Tue, 28 May 2013 09:48:49 +0000 (11:48 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Tue, 28 May 2013 09:48:49 +0000 (11:48 +0200)
we shall stay with DISTRIBUTION envionment variable yet: let's force the user to
provide the necessary distribution in Jenkins GUI or in call_jenkins.
in the next step we try to remove this parameter from jenkins and base the
decision of what distribution to use on what we find in the changelog. question
to be answered for this:
 stable -> squeeze?
 our old values like 'production', pau, ppu, ... -> ??
 wheezy -> wheezy?

the check_call() method from subprocess seems to return the exit code of command
ran as int. this doesn't behave well in current if-syntax, so we changed it to
match for success code "0" explicitely.

debian_build.py

index 114ba16f7a4975427d5bb29a273c46d0a12d6a0c..1fd9f3c95c3b781226c7930913a4c1d8b596e388 100755 (executable)
@@ -149,8 +149,8 @@ if __name__ == '__main__':
     # Act II: make decissions
     # compatibility until call_jenkins was replaced
     if ENV['DISTRIBUTION'] not in ('squeeze','wheezy'):
-        logger.warn('Compatbility Mode: Change distribution {old} => {new}.'.format(
-            old = ENV['DISTRIBUTION'],
+        logger.warn('Compatibility Mode: Change distribution {old} => {new}.'.format(
+            old = ENV['DISTRIBUTIONS'],
             new = 'squeeze'
             ))
         ENV['DISTRIBUTION'] = 'squeeze'
@@ -166,13 +166,14 @@ if __name__ == '__main__':
             exit_error()
         new_dist = 'stable'
         new_version = '{version}'.format(version = curr_version)
-        pb_suite = 'master-' + curr_dist
-        reprepro_base = '/srv/pb-' + curr_dist
+        pb_suite = 'master-' + ENV['DISTRIBUTION']
+        reprepro_base = '/srv/pb-' + ENV['DISTRIBUTION']
 
         # replace valid debian version chars that are invalid for git tagging
         new_tag = curr_version.replace('~','_')
         new_tag = new_tag.replace(':',',')
         # .. only take care of changelog automation if we want it to
+        # FIXME: this must be reponame in ...
         if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
             do_autoincrement = True
         # reset actions
@@ -206,8 +207,8 @@ if __name__ == '__main__':
             build = ENV['BUILD_NUMBER'],
             commit = curr_commit_id[0:7],
             )
-        pb_suite = 'develop-' + curr_dist
-        reprepro_base = '/srv/pb-' + curr_dist
+        pb_suite = 'develop-' + ENV['DISTRIBUTION']
+        reprepro_base = '/srv/pb-' + ENV['DISTRIBUTION']
         # reset actions
         # .. always include successful build packages into CIDB
         if ENV['DISTRIBUTION'] == 'squeeze':
@@ -220,15 +221,15 @@ if __name__ == '__main__':
                 ))
             exit_error()
 
-        new_dist = 'dev-' + ENV['GIT_BRANCH'].replace("/","-")
+        new_dist = 'dev-' + local_branch.replace("/","-")
         new_version = '{version}~experimental{date}+{build}+{commit}'.format(
             version = curr_version,
             date = daily_date,
             build = ENV['BUILD_NUMBER'],
             commit = curr_commit_id[0:7],
             )
-        pb_suite = 'experimental-' + curr_dist
-        reprepro_base = '/srv/dev-' + curr_dist
+        pb_suite = 'experimental-' + ENV['DISTRIBUTION']
+        reprepro_base = '/srv/dev-' + ENV['DISTRIBUTION']
 
     else:
         logger.error('Don\'t know how to handle branch "{branch}".'.format(
@@ -268,7 +269,7 @@ if __name__ == '__main__':
     logger.debug('Version: "%s" => "%s"' %(curr_version, new_version))
     logger.debug('PB_SUITE: ' + pb_suite)
     if do_triggers:
-        logger.debug('Triggers found: ' + commit_triggers)
+        logger.debug('Triggers found: ' + ', '.join(commit_triggers))
     if do_tagging:
         logger.debug('Tag to create: ' + new_tag)
     logger.debug('Upload configuration:\n%s' %(pformat(dput_obj.contents)))
@@ -304,7 +305,7 @@ if __name__ == '__main__':
             if len(files) > 0:
                 logger.info('Delete previous upstream tarball(s)')
                 cmd = [BIN_SUDO, BIN_RM, '-v'] + files
-                if subprocess.check_call(cmd):
+                if subprocess.check_call(cmd) == 0:
                     logger.info('%s succeeded.' % cmd)
                 else:
                     logger.warn('%s failed.' % cmd)
@@ -320,9 +321,9 @@ if __name__ == '__main__':
                 logger.info('Force building with tests as we also merge your branch.')
                 commit_triggers.remove('no-test')
 
-            src_branch = ENV['GIT_BRANCH']   # save the original branch
+            src_branch = local_branch        # save the original branch
             dst_branch = 'integration'       # define the new branch
-            ENV['GIT_BRANCH'] = dst_branch   # reset env for git-buildpackage
+            local_branch = dst_branch        # reset env for git-buildpackage
             # FIXME: error handling when rebase doesn't cleanly complete?
             gitrepo.git.rebase('--onto', dst_branch, src_branch)
             gitrepo.git.checkout(dst_branch)
@@ -406,8 +407,8 @@ if __name__ == '__main__':
     # ACT IV: preparations are done, let's build
     logger.info('Building ...')
     gbp = git_buildpackage.GitBuildPackage(
-        upstream_branch = ENV['GIT_BRANCH'],
-        debian_branch = ENV['GIT_BRANCH'],
+        upstream_branch = local_branch,
+        debian_branch = local_branch,
         dist = ENV['DISTRIBUTION'],
         arch = 'amd64',
         pb_suite = pb_suite,
@@ -444,10 +445,10 @@ if __name__ == '__main__':
             if os.path.exists(reports_file):
                 for cmd in (['/bin/tar', 'xzvf', reports_file, '-C', ENV['WORKSPACE']],
                             ['/usr/bin/sudo' , '/bin/rm', '-v', reports_file]):
-                    if not subprocess.check_call(cmd):
-                        logger.warn(cmd + ' failed.')
-                    else:
+                    if subprocess.check_call(cmd) == 0:
                         logger.info(cmd + ' succeeded.')
+                    else:
+                        logger.warn(cmd + ' failed.')
             else:
                 logger.info('No reports found.')
             figlet('Reports OK')