Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-2960

Stop build script feature - Something to run when a build is cancelled / stopped

    XMLWordPrintable

Details

    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

    Description

      Currently in Bamboo you cant stop a build once it has left the queue and is in progress. The problem is made more intractable because Bamboo doesnt really know what build processes to stop.

      I am proposing that we put a feature in Bamboo build configuration that would be a "program to run on Build cancel". This would be invoked if the user presses the Cancel build button whena build is in progress.

      This program would be given 3 arguments. The process id the build process in question, the build plan and the buld number say. Perhaps other Bamboo properties could eb stuffed into the process environment as well.

      This would allow the "stop process" to do what ever it needs to do to stop the build from running. This might be a kill -9 style script under Unix or a clean shutdown program.

      The key point here is that Bamboo does not take on the reposibility of being able to stop a build proccess (and all the support questions that would raise) but rather allows customers to have a mechanism to clean up running builds.

      Maybe a database needs to be cleanly shutdown, or a TCP connection to a POS terminal emulator. There are all sorts of clean up tasks that a build might need. We just need to give them enough information to write such a script.

      I would advocate that Bamboo have a simple "shim" program that it used to start any process. So this would produce a shim per build like

      BAMBOO ----
                          shim build123 -----
                                                     maven xxxx xxx -------
                                                                                         andsoon
                          shim build456 -----
                                                     maven xxxx xxx -------
                                                                                         andsoon
      

      The shim would simple report its process id back to Bamboo via stdout/stderr and then Bamboo knows what COULD be killed, eg all the programs of and including shim xyz

      The parameters to the shim would be the project/plan/build number so that when someone looks ate the running processes (via say ps) they can easily identify the builds. The rest of the parameters would be the build command to run.

      So for example the shim program invocation might look like

      shim "JIRA Unit Tests - HEAD" "JDK1.6" "BASIC-JDK16-3645" maven clean test

      And the first line of stdout might be

      pid=323455
        	 __  __
       	|  \/  |__ _Apache__ ___
       	| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
       	|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2
       	
       	build:start:
       	
       	clean:clean:
       	    [delete] Deleting directory /home/jira2-bamboo-j2ee/bamboo-home/xml-data/build-dir/BASIC-JDK16/target
      ...
      ...
      ...
      

      then followed by the builder output.

      As for finding out the current Java process id, there are two solid approaches. The first is to use JMX on Java5 or above. This works reliably on Sun JVM's on Windows and Unix.

      ManagementFactory.getRuntimeMXBean().getName();
      

      The other is to use JNA. I have spiked this on both Windows and Linux with great success.

      http://jna.dev.java.net/

      public class JNAProcessKit
      {
          private interface CLibrary extends Library
          {
              final static CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
      
      
              /**
               * On POSIX its called getpid()
               */
              int getpid();
      
              /**
               * On Win32 C runtime its called _getpid()
               */
              int _getpid();
          }
      
          public static int getPID()
          {
              int pid = 0;
              if (Platform.isWindows())
              {
                  pid = CLibrary.INSTANCE._getpid();
              }
              else
              {
                  pid = CLibrary.INSTANCE.getpid();
              }
              return pid;
          }
      }
      

      Once we have the process id of the shim, we then have a place that peole can terminate a running. Also the user of the shim will mean the builds will turn up more easily in process viewers like
      ps.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bbaker ɹǝʞɐq pɐɹq
              Votes:
              6 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: