├── .idea ├── .name ├── codeStyles │ └── codeStyleConfig.xml ├── vcs.xml ├── encodings.xml ├── modules.xml ├── compiler.xml └── misc.xml ├── src └── main │ ├── resources │ ├── index.jelly │ └── com │ │ └── abhyudayasharma │ │ └── jenkins │ │ └── diskthreshold │ │ ├── Messages.properties │ │ └── DiskThresholdJobProperty │ │ └── config-details.jelly │ └── java │ └── com │ └── abhyudayasharma │ └── jenkins │ └── diskthreshold │ ├── DiskThresholdQueueDecisionHandler.java │ └── DiskThresholdJobProperty.java ├── LICENSE ├── .gitignore ├── pom.xml └── demo.iml /.idea/.name: -------------------------------------------------------------------------------- 1 | demo -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 |
2 | Disk Threshold Plugin 3 |
-------------------------------------------------------------------------------- /src/main/resources/com/abhyudayasharma/jenkins/diskthreshold/Messages.properties: -------------------------------------------------------------------------------- 1 | DisplayName=Disk Full Threshold 2 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/com/abhyudayasharma/jenkins/diskthreshold/DiskThresholdJobProperty/config-details.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Abhyudaya Sharma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/**/usage.statistics.xml 8 | .idea/**/dictionaries 9 | .idea/**/shelf 10 | 11 | # Generated files 12 | .idea/**/contentModel.xml 13 | 14 | # Sensitive or high-churn files 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | .idea/**/dbnavigator.xml 22 | 23 | # Gradle 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # Gradle and Maven with auto-import 28 | # When using Gradle or Maven with auto-import, you should exclude module files, 29 | # since they will be recreated, and may cause churn. Uncomment if using 30 | # auto-import. 31 | # .idea/modules.xml 32 | # .idea/*.iml 33 | # .idea/modules 34 | 35 | # CMake 36 | cmake-build-*/ 37 | 38 | # Mongo Explorer plugin 39 | .idea/**/mongoSettings.xml 40 | 41 | # File-based project format 42 | *.iws 43 | 44 | # IntelliJ 45 | out/ 46 | 47 | # mpeltonen/sbt-idea plugin 48 | .idea_modules/ 49 | 50 | # JIRA plugin 51 | atlassian-ide-plugin.xml 52 | 53 | # Cursive Clojure plugin 54 | .idea/replstate.xml 55 | 56 | # Crashlytics plugin (for Android Studio and IntelliJ) 57 | com_crashlytics_export_strings.xml 58 | crashlytics.properties 59 | crashlytics-build.properties 60 | fabric.properties 61 | 62 | # Editor-based Rest Client 63 | .idea/httpRequests 64 | 65 | # Android studio 3.1+ serialized cache file 66 | .idea/caches/build_file_checksums.ser 67 | 68 | work 69 | target 70 | -------------------------------------------------------------------------------- /src/main/java/com/abhyudayasharma/jenkins/diskthreshold/DiskThresholdQueueDecisionHandler.java: -------------------------------------------------------------------------------- 1 | package com.abhyudayasharma.jenkins.diskthreshold; 2 | 3 | import hudson.Extension; 4 | import hudson.model.AbstractProject; 5 | import hudson.model.Action; 6 | import hudson.model.Job; 7 | import hudson.model.JobProperty; 8 | import hudson.model.Queue; 9 | import jenkins.model.Jenkins; 10 | 11 | import java.util.List; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | 15 | @Extension 16 | public class DiskThresholdQueueDecisionHandler extends Queue.QueueDecisionHandler { 17 | private static Logger LOGGER = Logger.getLogger(DiskThresholdQueueDecisionHandler.class.getName()); 18 | 19 | @Override 20 | public boolean shouldSchedule(Queue.Task p, List actions) { 21 | AbstractProject project = (AbstractProject) p; 22 | for (Object o : project.getAllJobs()) { 23 | Job job = (Job) o; 24 | JobProperty prop = job.getProperty(DiskThresholdJobProperty.class); 25 | if (prop instanceof DiskThresholdJobProperty) { // instanceof checks for null 26 | DiskThresholdJobProperty property = (DiskThresholdJobProperty) prop; 27 | long usableSpace = Jenkins.getInstance().getRootDir().getUsableSpace(); 28 | long thresholdBytes = property.getThresholdMegaBytes() * 1024 * 1024; // convert to bytes from MBs 29 | if (usableSpace < thresholdBytes) { 30 | LOGGER.log(Level.SEVERE, "Not adding task to Queue due to limited disk space. " + 31 | "Current free disk space: " + usableSpace); 32 | return false; 33 | } 34 | } 35 | } 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/abhyudayasharma/jenkins/diskthreshold/DiskThresholdJobProperty.java: -------------------------------------------------------------------------------- 1 | package com.abhyudayasharma.jenkins.diskthreshold; 2 | 3 | import hudson.Extension; 4 | import hudson.util.FormValidation; 5 | import jenkins.model.OptionalJobProperty; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.kohsuke.stapler.DataBoundSetter; 8 | import org.kohsuke.stapler.QueryParameter; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | @SuppressWarnings("unused") 13 | public final class DiskThresholdJobProperty extends OptionalJobProperty { 14 | 15 | @Extension 16 | public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); 17 | private final static transient long MINIMUM_THRESHOLD_MEGABYTES = 1; 18 | private long thresholdMegaBytes; 19 | 20 | @DataBoundConstructor 21 | public DiskThresholdJobProperty(long thresholdMegaBytes) { 22 | this.thresholdMegaBytes = thresholdMegaBytes; 23 | } 24 | 25 | /** 26 | * Get the threshold bytes 27 | * 28 | * @return threshold bytes 29 | */ 30 | @SuppressWarnings("WeakerAccess") 31 | public long getThresholdMegaBytes() { 32 | return thresholdMegaBytes; 33 | } 34 | 35 | /** 36 | * Set thresholdMegaBytes 37 | * 38 | * @param thresholdMegaBytes the threshold to disk full in bytes 39 | */ 40 | @DataBoundSetter 41 | public void setThresholdMegaBytes(long thresholdMegaBytes) { 42 | this.thresholdMegaBytes = thresholdMegaBytes; 43 | } 44 | 45 | public static final class DescriptorImpl extends OptionalJobPropertyDescriptor { 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Nonnull 51 | @Override 52 | public String getDisplayName() { 53 | return Messages.DisplayName(); 54 | } 55 | 56 | /** 57 | * Check and validate the value of thresholdMegaBytes entered by the user 58 | * 59 | * @param value the entered value 60 | * @return OK if validated, Error otherwise 61 | */ 62 | public FormValidation doCheckThresholdMegaBytes(@QueryParameter String value) { 63 | try { 64 | Long l = Long.valueOf(value); 65 | if (l > MINIMUM_THRESHOLD_MEGABYTES) return FormValidation.ok(); 66 | } catch (NumberFormatException ignore) { 67 | } 68 | return FormValidation.error("Please enter a positive integer value greater than " + 69 | MINIMUM_THRESHOLD_MEGABYTES + "."); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.jenkins-ci.plugins 6 | plugin 7 | 3.4 8 | 9 | 10 | io.jenkins.plugins 11 | disk-threshold 12 | 1.0-SNAPSHOT 13 | hpi 14 | 15 | 16 | 2.7.3 17 | 8 18 | 23 | 24 | Disk Threshold plugin 25 | Stops adding builds to the queue when disk is full. 26 | 27 | 28 | 29 | MIT License 30 | https://opensource.org/licenses/MIT 31 | 32 | 33 | 34 | 35 | org.jenkins-ci.plugins 36 | structs 37 | 1.7 38 | 39 | 40 | org.jenkins-ci.plugins.workflow 41 | workflow-step-api 42 | 2.12 43 | test 44 | 45 | 46 | org.jenkins-ci.plugins.workflow 47 | workflow-cps 48 | 2.39 49 | test 50 | 51 | 52 | org.jenkins-ci.plugins.workflow 53 | workflow-job 54 | 2.11.2 55 | test 56 | 57 | 58 | org.jenkins-ci.plugins.workflow 59 | workflow-basic-steps 60 | 2.6 61 | test 62 | 63 | 64 | org.jenkins-ci.plugins.workflow 65 | workflow-durable-task-step 66 | 2.13 67 | test 68 | 69 | 70 | org.jenkins-ci.plugins.workflow 71 | workflow-api 72 | 2.20 73 | test 74 | 75 | 76 | org.jenkins-ci.plugins.workflow 77 | workflow-support 78 | 2.14 79 | test 80 | 81 | 82 | 83 | 84 | 85 | AbhyudayaSharma 86 | Abhyudaya Sharma 87 | sharmaabhyudaya@gmail.com 88 | 89 | 90 | 91 | 99 | 100 | 101 | repo.jenkins-ci.org 102 | https://repo.jenkins-ci.org/public/ 103 | 104 | 105 | 106 | 107 | repo.jenkins-ci.org 108 | https://repo.jenkins-ci.org/public/ 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /demo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | --------------------------------------------------------------------------------