PageRenderTime 89ms CodeModel.GetById 33ms RepoModel.GetById 2ms app.codeStats 0ms

/seed-plugin/src/main/groovy/net/nemerosa/jenkins/seed/generator/BranchDestructionStep.java

https://gitlab.com/vectorci/seed-plugin
Java | 82 lines | 59 code | 16 blank | 7 comment | 0 complexity | b10d5ed9f0140542bf9ff69a18544b01 MD5 | raw file
  1. package net.nemerosa.jenkins.seed.generator;
  2. import com.google.inject.Guice;
  3. import hudson.EnvVars;
  4. import hudson.Extension;
  5. import hudson.Launcher;
  6. import hudson.model.AbstractBuild;
  7. import hudson.model.AbstractProject;
  8. import hudson.model.BuildListener;
  9. import hudson.tasks.BuildStepDescriptor;
  10. import hudson.tasks.Builder;
  11. import net.nemerosa.jenkins.seed.triggering.*;
  12. import org.kohsuke.stapler.DataBoundConstructor;
  13. import java.io.IOException;
  14. /**
  15. * Configuration of a Project job when it's time to generate/update a branch.
  16. */
  17. public class BranchDestructionStep extends Builder {
  18. private final String project;
  19. private final String branch;
  20. @DataBoundConstructor
  21. public BranchDestructionStep(String project, String branch) {
  22. this.project = project;
  23. this.branch = branch;
  24. }
  25. protected SeedService getSeedService() {
  26. return Guice.createInjector(new SeedServiceModule()).getInstance(SeedService.class);
  27. }
  28. @Override
  29. public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
  30. SeedService seedService = getSeedService();
  31. // Environment for the DSL execution
  32. EnvVars env = build.getEnvironment(listener);
  33. env.putAll(build.getBuildVariables());
  34. // Gets actual properties
  35. String theProject = env.expand(project);
  36. String theBranch = env.expand(branch);
  37. // Posts an event for the destruction of the branch
  38. seedService.post(
  39. new SeedEvent(
  40. theProject,
  41. theBranch,
  42. SeedEventType.DELETION,
  43. SeedChannel.SYSTEM
  44. )
  45. );
  46. // OK
  47. return true;
  48. }
  49. public String getProject() {
  50. return project;
  51. }
  52. public String getBranch() {
  53. return branch;
  54. }
  55. @Extension
  56. public static class BranchDestructionStepExtension extends BuildStepDescriptor<Builder> {
  57. @Override
  58. public boolean isApplicable(Class<? extends AbstractProject> jobType) {
  59. return true;
  60. }
  61. @Override
  62. public String getDisplayName() {
  63. return "Seed - Branch folder deletion";
  64. }
  65. }
  66. }