]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build.py: Upload to apt01 first and store changed .changes file separately.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Fri, 6 Jun 2014 15:12:15 +0000 (17:12 +0200)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Fri, 6 Jun 2014 15:12:15 +0000 (17:12 +0200)
debian_build.py

index d59a8a6be0b96a9d4089d1302233bbf7cbba467f..f255dfbfe22e62f6d6e5a824624bcfea1576a0a7 100755 (executable)
@@ -107,26 +107,35 @@ def getopts():
 def upload_to_apt_repository(apt_target, apt_dist, changes_file, logger):
     try:
         # Change distribution for new apt repository in changes file
-        cmd = ['sed', '-i', r's/^\(Distribution: \).*$/\1' + apt_dist + '/',
-               changes_file]
+        cmd = ['sed', r's/^\(Distribution: \).*$/\1' + apt_dist + '/', changes_file]
         command = ' '.join(cmd)
         logger.debug('Executing "{command}" ...'.format(command=command))
-        if subprocess.call(cmd) == 0:
+        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+        changes = process.communicate()[0]
+        if process.returncode == 0:
             logger.debug('%s succeeded.' % command)
         else:
             logger.warn('%s failed.' % command)
+            figlet('apt01 upload failed')
             return
+        new_changes_file = os.path.join(ENV['WORKSPACE'], apt_target + '.changes')
+        filehandle = open(new_changes_file, 'w')
+        filehandle.write(changes)
+        filehandle.close()
 
-        cmd = ['dput', apt_target, changes_file]
+        cmd = ['dput', apt_target, new_changes_file]
         command = ' '.join(cmd)
         logger.debug('Executing "{command}" ...'.format(command=command))
         if subprocess.call(cmd) == 0:
             logger.debug('%s succeeded.' % command)
+            figlet('apt01 upload OK')
         else:
             logger.warn('%s failed.' % command)
+            figlet('apt01 upload failed')
     except Exception as error:
         logger.warning("Experimental upload to http://apt01.pb.local failed. "
                        "See above for details.", exc_info=error)
+        figlet('apt01 upload failed')
 
 
 if __name__ == '__main__':
@@ -684,14 +693,15 @@ export {builder_env} FORCE_SHELL=TRUE
             ))
             fh.close()
 
+            # upload to new apt01 archive
+            upload_to_apt_repository(apt_target, apt_dist, changes_file, logger)
+
             # upload changes file
             dput_obj.configure()
             dput_obj.upload(changes_file)
 
             figlet('Upload OK')
 
-            upload_to_apt_repository(apt_target, apt_dist, changes_file, logger)
-
         except Exception as error:
             logger.error('Upload failed. See above for details.', exc_info=error)
             figlet('Upload failed')