Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-16758

Cannot stop a build from custom plugin using interrupt

XMLWordPrintable

      I have seen issues similar to this one but have not seen one that knew where the problem came from and the issue was usually described as coming from a Groovy script. At the company I work for I created a custom plugin that is suppose to check a couple of build parameters and if they do not validate we should not allow the build to continue. The plugin is an extension of the RunListener<AbstractBuild> class and we make use of the onStarted method. With this the plugin should run before any other tasks but after the build parameter formats are checked via the ValidatingStringParameter plugin. After this check our plugin runs. It is suppose to validate the build parameters against the database and if there are any problems we attempt to run the following 2 lines.

      build.setResult(Result.FAILURE);
      build.getExecutor().interrupt(Result.FAILURE);

      Problem is that these 2 lines do not always work. I first discovered this on one of our test jenkin installs which was version 1.489. After Googling, some have suggested throwing an exception. So I forced the code to throw a NumberFormatException when the first attempt to stop the build did not work and that fixed the problem there. I am attaching SUDO code of how the class looks.

      Problem now is that this also does not work every time. Particularly when you configure your job to check out from SVN and set the "Check-out Strategy" to "Always checkout a fresh copy". The final status of the build is set to FAILURE and shows the red status indicator but the build still runs and is completed. It seems as if having this overrides the interrupt request. I would understand if after the SVN update happened the build stopped but it does not. However, if the Check-out Strategy is set to "Use 'svn update' as much as possible" the plugin is able to stop the build. The last log messages when the stop is successful is below.

      Updating svn://myServer/MyRepo/MyProject/trunk
      ERROR: Subversion update has been canceled
      Build was aborted
      Finished: FAILURE

      So that is basically the bug. When the SVN Check-out Strategy is set to "Always checkout a fresh copy" I cannot stop the build. It continues to the end. I would also like to avoid forcing the code to throw an exception in version 1.489 if possible. It requires a variable that is only needed for that issue(failed) and a block of code that makes me cringe every time I see it.

            Unassigned Unassigned
            bigeazy73 Eddie M
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: