├── src ├── main │ ├── resources │ │ ├── index.jelly │ │ └── io │ │ │ └── jenkins │ │ │ └── plugins │ │ │ └── agentManager │ │ │ ├── HelloWorldBuilder │ │ │ ├── help-name.html │ │ │ ├── help-name_tr.html │ │ │ ├── help-name_es.html │ │ │ ├── help-name_fr.html │ │ │ ├── help-name_pt_BR.html │ │ │ ├── help-name_sv.html │ │ │ ├── help-name_it.html │ │ │ ├── help-useFrench.html │ │ │ ├── help-useFrench_pt_BR.html │ │ │ ├── help-useFrench_sv.html │ │ │ ├── help-useFrench_tr.html │ │ │ ├── help-name_de.html │ │ │ ├── help-useFrench_es.html │ │ │ ├── help-useFrench_fr.html │ │ │ ├── help-useFrench_it.html │ │ │ ├── config.properties │ │ │ ├── config_it.properties │ │ │ ├── help-useFrench_de.html │ │ │ ├── config_sv.properties │ │ │ ├── config_es.properties │ │ │ ├── config_pt_BR.properties │ │ │ ├── config_fr.properties │ │ │ ├── config_tr.properties │ │ │ ├── config_de.properties │ │ │ ├── config_zh_CN.properties │ │ │ ├── help-name_zh_CN.html │ │ │ ├── help-useFrench_zh_CN.html │ │ │ └── config.jelly │ │ │ ├── Actions │ │ │ ├── PostBuild │ │ │ │ ├── Cleanup │ │ │ │ │ └── config.jelly │ │ │ │ ├── Reboot │ │ │ │ │ └── config.jelly │ │ │ │ ├── SetOffline │ │ │ │ │ └── config.jelly │ │ │ │ ├── StopBuild │ │ │ │ │ └── config.jelly │ │ │ │ ├── GracefulReboot │ │ │ │ │ └── config.jelly │ │ │ │ ├── GroovyScript │ │ │ │ │ └── config.jelly │ │ │ │ └── ShellScript │ │ │ │ │ └── config.jelly │ │ │ ├── PreBuild │ │ │ │ ├── Cleanup │ │ │ │ │ └── config.jelly │ │ │ │ ├── Reboot │ │ │ │ │ └── config.jelly │ │ │ │ ├── SetOffline │ │ │ │ │ └── config.jelly │ │ │ │ ├── StopBuild │ │ │ │ │ └── config.jelly │ │ │ │ ├── GracefulReboot │ │ │ │ │ └── config.jelly │ │ │ │ ├── GroovyScript │ │ │ │ │ └── config.jelly │ │ │ │ └── ShellScript │ │ │ │ │ └── config.jelly │ │ │ └── DuringBuild │ │ │ │ ├── Cleanup │ │ │ │ └── config.jelly │ │ │ │ ├── Reboot │ │ │ │ └── config.jelly │ │ │ │ ├── SetOffline │ │ │ │ └── config.jelly │ │ │ │ ├── StopBuild │ │ │ │ └── config.jelly │ │ │ │ ├── GracefulReboot │ │ │ │ └── config.jelly │ │ │ │ ├── ShellScript │ │ │ │ └── config.jelly │ │ │ │ └── GroovyScript │ │ │ │ └── config.jelly │ │ │ ├── Conditions │ │ │ ├── DuringBuild │ │ │ │ ├── NoCondition │ │ │ │ │ └── config.jelly │ │ │ │ ├── Script │ │ │ │ │ └── config.jelly │ │ │ │ ├── HistoryFailed │ │ │ │ │ └── config.jelly │ │ │ │ ├── DiskSpace │ │ │ │ │ └── config.jelly │ │ │ │ └── HistoryTime │ │ │ │ │ └── config.jelly │ │ │ ├── PostBuild │ │ │ │ ├── NoCondition │ │ │ │ │ └── config.jelly │ │ │ │ ├── Script │ │ │ │ │ └── config.jelly │ │ │ │ ├── HistoryFailed │ │ │ │ │ └── config.jelly │ │ │ │ ├── DiskSpace │ │ │ │ │ └── config.jelly │ │ │ │ ├── Duration │ │ │ │ │ └── config.jelly │ │ │ │ ├── HistoryTime │ │ │ │ │ └── config.jelly │ │ │ │ └── Result │ │ │ │ │ └── config.jelly │ │ │ └── PreBuild │ │ │ │ ├── NoCondition │ │ │ │ └── config.jelly │ │ │ │ ├── Script │ │ │ │ └── config.jelly │ │ │ │ ├── HistoryFailed │ │ │ │ └── config.jelly │ │ │ │ ├── DiskSpace │ │ │ │ └── config.jelly │ │ │ │ └── HistoryTime │ │ │ │ └── config.jelly │ │ │ ├── Messages.properties │ │ │ ├── Messages_sv.properties │ │ │ ├── Messages_de.properties │ │ │ ├── Messages_fr.properties │ │ │ ├── Messages_pt_BR.properties │ │ │ ├── Messages_es.properties │ │ │ ├── Messages_it.properties │ │ │ ├── Messages_tr.properties │ │ │ ├── Messages_zh_CN.properties │ │ │ ├── BuildEntries │ │ │ ├── PreBuildEntry │ │ │ │ └── config.jelly │ │ │ ├── PostBuildEntry │ │ │ │ └── config.jelly │ │ │ └── DuringBuildEntry │ │ │ │ └── config.jelly │ │ │ └── NodePropertyImpl │ │ │ └── config.jelly │ └── java │ │ └── io │ │ └── jenkins │ │ └── plugins │ │ └── agentManager │ │ ├── Conditions │ │ ├── Condition.java │ │ ├── NoCondition.java │ │ ├── PreBuildCondition.java │ │ ├── PostBuildCondition.java │ │ ├── DuringBuildCondition.java │ │ ├── PreBuild │ │ │ ├── Script.java │ │ │ ├── NoCondition.java │ │ │ ├── HistoryTime.java │ │ │ ├── DiskSpace.java │ │ │ └── HistoryFailed.java │ │ ├── PostBuild │ │ │ ├── Script.java │ │ │ ├── NoCondition.java │ │ │ ├── HistoryTime.java │ │ │ ├── Result.java │ │ │ ├── DiskSpace.java │ │ │ ├── HistoryFailed.java │ │ │ └── Duration.java │ │ ├── DuringBuild │ │ │ ├── Script.java │ │ │ ├── NoCondition.java │ │ │ ├── HistoryTime.java │ │ │ ├── DiskSpace.java │ │ │ └── HistoryFailed.java │ │ ├── Script.java │ │ ├── HistoryFailed.java │ │ ├── HistoryTime.java │ │ ├── DiskSpace.java │ │ ├── Duration.java │ │ └── Result.java │ │ ├── Actions │ │ ├── Action.java │ │ ├── SetOffline.java │ │ ├── Reboot.java │ │ ├── PreBuildAction.java │ │ ├── PostBuildAction.java │ │ ├── DuringBuildAction.java │ │ ├── PostBuild │ │ │ ├── Reboot.java │ │ │ ├── GracefulReboot.java │ │ │ ├── ShellScript.java │ │ │ ├── GroovyScript.java │ │ │ ├── Cleanup.java │ │ │ ├── StopBuild.java │ │ │ └── SetOffline.java │ │ ├── DuringBuild │ │ │ ├── Reboot.java │ │ │ ├── GracefulReboot.java │ │ │ ├── ShellScript.java │ │ │ ├── GroovyScript.java │ │ │ ├── Cleanup.java │ │ │ ├── StopBuild.java │ │ │ └── SetOffline.java │ │ ├── PreBuild │ │ │ ├── Cleanup.java │ │ │ ├── SetOffline.java │ │ │ ├── StopBuild.java │ │ │ ├── GroovyScript.java │ │ │ └── ShellScript.java │ │ ├── StopBuild.java │ │ ├── ShellScript.java │ │ ├── GroovyScript.java │ │ ├── GracefulReboot.java │ │ └── Cleanup.java │ │ ├── BuildEntries │ │ ├── BuildEntry.java │ │ ├── PreBuildEntry.java │ │ ├── PostBuildEntry.java │ │ └── DuringBuildEntry.java │ │ ├── Utils │ │ ├── Time.java │ │ ├── ShellScriptRunner.java │ │ ├── HelperActions.java │ │ └── GroovyScriptRunner.java │ │ ├── NodePropertyImpl.java │ │ ├── RunListenerImpl.java │ │ └── ActionRunner.java └── test │ └── java │ └── io │ └── jenkins │ └── plugins │ └── agentManager │ ├── TestHelper.java │ ├── ActionGracefulRebootTest.java │ ├── PostBuildTest.java │ ├── ActionRebootTest.java │ ├── PreBuildTest.java │ ├── ConditionNoConditionTest.java │ ├── ConditionDurationTest.java │ ├── ConditionResultTest.java │ ├── ConditionScriptTest.java │ ├── ConditionHistoryFailedTest.java │ ├── ConditionHistoryTimeTest.java │ └── DuringBuildTest.java ├── Jenkinsfile └── pom.xml /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | TODO 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name.html: -------------------------------------------------------------------------------- 1 |
2 | Your name. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_tr.html: -------------------------------------------------------------------------------- 1 |
2 | İsmin. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_es.html: -------------------------------------------------------------------------------- 1 |
2 | Tu nombre. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_fr.html: -------------------------------------------------------------------------------- 1 |
2 | Votre nom. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Seu nome. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_sv.html: -------------------------------------------------------------------------------- 1 |
2 | Ditt namn. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_it.html: -------------------------------------------------------------------------------- 1 |
2 | Nome di mostrare. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench.html: -------------------------------------------------------------------------------- 1 |
2 | Use French? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Usar francês? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_sv.html: -------------------------------------------------------------------------------- 1 |
2 | Använda Franska? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_tr.html: -------------------------------------------------------------------------------- 1 |
2 | Fransızca göster? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_de.html: -------------------------------------------------------------------------------- 1 |
2 | Geben Sie Ihren Namen ein. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_es.html: -------------------------------------------------------------------------------- 1 |
2 | ¿Utilizar el francés? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_fr.html: -------------------------------------------------------------------------------- 1 |
2 | Utiliser le français ? 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_it.html: -------------------------------------------------------------------------------- 1 |
2 | Mostrare il messagio in francese. 3 |
4 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /* 2 | See the documentation for more options: 3 | https://github.com/jenkins-infra/pipeline-library/ 4 | */ 5 | buildPlugin(useContainerAgent: true) 6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config.properties: -------------------------------------------------------------------------------- 1 | Name=Name 2 | French=French 3 | FrenchDescr=Check if we should say hello in French -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_it.properties: -------------------------------------------------------------------------------- 1 | Name=Nome 2 | French=Francese 3 | FrenchDescr=Mostra il messagio in francese 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_de.html: -------------------------------------------------------------------------------- 1 |
2 | Ob die Begrüßung auf französisch angegeben werden soll. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_sv.properties: -------------------------------------------------------------------------------- 1 | Name=Namn 2 | French=Franska 3 | FrenchDescr=S\u00E4tt om vi ska s\u00E4ga hej p\u00E5 Franska -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_es.properties: -------------------------------------------------------------------------------- 1 | Name=Nombre 2 | French=Franc\u00E9s 3 | FrenchDescr=Compruebe si debemos decir hola en franc\u00E9s -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_pt_BR.properties: -------------------------------------------------------------------------------- 1 | Name=Nome 2 | French=Franc\u00EAs 3 | FrenchDescr=Marque se devemos falar ol\u00E1 em franc\u00EAs -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/Cleanup/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/Reboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/Cleanup/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/Reboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_fr.properties: -------------------------------------------------------------------------------- 1 | Name=Nom 2 | French=Fran\u00e7ais 3 | FrenchDescr=V\u00e9rifie qu'on dit bien hello en fran\u00e7ais 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_tr.properties: -------------------------------------------------------------------------------- 1 | Name=\u0130sim 2 | French=Frans\u0131zca 3 | FrenchDescr=Frans\u0131zca olarak merhaba demeliyim diye sor -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/Cleanup/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/Reboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/SetOffline/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/StopBuild/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/SetOffline/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/StopBuild/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/SetOffline/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/StopBuild/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_de.properties: -------------------------------------------------------------------------------- 1 | Name=Name 2 | French=Franz\u00F6sisch 3 | FrenchDescr=Markieren f\u00FCr Begr\u00FC\u00DFung auf franz\u00F6sisch -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/GracefulReboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/GracefulReboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/GracefulReboot/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/DuringBuild/NoCondition/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/NoCondition/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PreBuild/NoCondition/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config_zh_CN.properties: -------------------------------------------------------------------------------- 1 | Name=\u540d\u5b57 2 | French=\u6cd5\u8bed 3 | FrenchDescr=\u68c0\u67e5\u6211\u4eec\u662f\u5426\u5e94\u8be5\u7528\u6cd5\u8bed\u6253\u4e2a\u62db\u547c -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-name_zh_CN.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 你的名字。 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/help-useFrench_zh_CN.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 使用法语 ? 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PreBuild/Script/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/ShellScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/GroovyScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PostBuild/ShellScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/GroovyScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/PreBuild/ShellScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/DuringBuild/Script/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/Script/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Actions/DuringBuild/GroovyScript/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PreBuild/HistoryFailed/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/DuringBuild/HistoryFailed/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/HistoryFailed/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Please set a name 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=Isn't the name too short? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=Are you actually French? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Say hello world -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_sv.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Ange ett namn 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=\u00C4r inte namnet lite f\u00F6r kort? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=\u00C4r du egentligen Fransk? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=S\u00E4g Hej V\u00E4rlden 6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_de.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Bitte geben Sie einen Namen an 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=Der Name ist zu kurz. 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=Sind Sie wirklich franz\u00F6sisch? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=\u201EHallo Welt\u201C sagen -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_fr.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Veuillez saisir un nom 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=Le nom n'est-il pas trop court ? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=\u00CAtes vous vraiment fran\u00E7ais ? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Dis hello world 6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_pt_BR.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Insira um nome 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=Este nome n\u00E3o \u00E9 muito curto? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=Voc\u00EA \u00E9 realmente franc\u00EAs? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Diz ol\u00E1 mundo -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_es.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Proporciona un nombre 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=\u00BFEl nombre no est\u00C1 demasiado corto? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=\u00BFRealmente eres franc\u00E9s? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Di hola mundo 6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_it.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=Nome \u00E8 richiesto 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=Il nome dev'essere lungo almeno 4 charatteri 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=Mostra il messaggio in francese? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Nome da mostrare 6 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/Condition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.TaskListener; 6 | 7 | public interface Condition { 8 | String getName(); 9 | 10 | boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) throws Exception; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_tr.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=L\u00FCtfen bir isim girin 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=\u0130sminiz \u00E7ok k\u0131sa de\u011Fil mi? 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=Ger\u00E7ekten Frans\u0131z m\u0131s\u0131n\u0131z? 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=Merhaba d\u00FCnya de 6 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PreBuild/DiskSpace/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/DuringBuild/DiskSpace/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/DiskSpace/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/Action.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.TaskListener; 7 | 8 | public interface Action { 9 | String getName(); 10 | 11 | void runAction(TaskListener listener, Launcher launcher, AbstractBuild run, Computer computer) throws Exception; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | HelloWorldBuilder.DescriptorImpl.errors.missingName=\u8bf7\u586b\u5199\u540d\u5b57 2 | HelloWorldBuilder.DescriptorImpl.warnings.tooShort=\u540d\u5b57\u662f\u4e0d\u662f\u592a\u77ed\u4e86\uff1f 3 | HelloWorldBuilder.DescriptorImpl.warnings.reallyFrench=\u4f60\u771f\u7684\u662f\u6cd5\u56fd\u4eba\u5417\uff1f 4 | 5 | HelloWorldBuilder.DescriptorImpl.DisplayName=\u8bf4\uff1a\u4f60\u597d\uff0c\u4e16\u754c -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/BuildEntries/BuildEntry.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.BuildEntries; 2 | 3 | import hudson.model.AbstractDescribableImpl; 4 | import io.jenkins.plugins.agentManager.Actions.Action; 5 | import io.jenkins.plugins.agentManager.Conditions.Condition; 6 | 7 | public abstract class BuildEntry extends AbstractDescribableImpl { 8 | public abstract Condition getCondition(); 9 | public abstract Action getAction(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/Duration/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/HistoryTime/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PreBuild/HistoryTime/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/DuringBuild/HistoryTime/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/BuildEntries/PreBuildEntry/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/BuildEntries/PostBuildEntry/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/HelloWorldBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/Conditions/PostBuild/Result/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/NoCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.TaskListener; 6 | 7 | public abstract class NoCondition implements Condition { 8 | public NoCondition() { 9 | } 10 | 11 | @Override 12 | public String getName() { 13 | return "NoCondition"; 14 | } 15 | 16 | @Override 17 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 18 | return true; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuildCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | public interface PreBuildCondition extends ExtensionPoint, Describable, Condition { 9 | default Descriptor getDescriptor() { 10 | return Jenkins.get().getDescriptor(getClass()); 11 | } 12 | 13 | class PreBuildConditionDescriptor extends Descriptor {} 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuildCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | public interface PostBuildCondition extends ExtensionPoint, Describable, Condition { 9 | default Descriptor getDescriptor() { 10 | return Jenkins.get().getDescriptor(getClass()); 11 | } 12 | 13 | class PostBuildConditionDescriptor extends Descriptor {} 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuildCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | public interface DuringBuildCondition extends ExtensionPoint, Describable, Condition { 9 | default Descriptor getDescriptor() { 10 | return Jenkins.get().getDescriptor(getClass()); 11 | } 12 | 13 | class DuringBuildConditionDescriptor extends Descriptor {} 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/SetOffline.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.Messages; 5 | import hudson.model.*; 6 | import hudson.slaves.OfflineCause; 7 | import io.jenkins.plugins.agentManager.Utils.HelperActions; 8 | import org.jvnet.localizer.ResourceBundleHolder; 9 | 10 | public abstract class SetOffline implements Action { 11 | @Override 12 | public String getName() { 13 | return "SetOffline"; 14 | } 15 | 16 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild build, Computer computer) { 17 | HelperActions.setAgentOffline(listener, launcher, build, computer); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/Reboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.TaskListener; 7 | import io.jenkins.plugins.agentManager.Utils.HelperActions; 8 | import io.jenkins.plugins.agentManager.Utils.ShellScriptRunner; 9 | 10 | public abstract class Reboot implements Action { 11 | @Override 12 | public String getName() { 13 | return "Reboot"; 14 | } 15 | 16 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild run, Computer computer) { 17 | HelperActions.rebootAgent(listener, launcher, computer); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuildAction.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | // TODO for thesis text: 9 | // MAKE This interface instead of abstract class because when some classes will implement this, classes can extend multiple interface, but no multiple abstract classes 10 | public interface PreBuildAction extends ExtensionPoint, Describable, Action { 11 | default Descriptor getDescriptor() { 12 | return Jenkins.get().getDescriptor(getClass()); 13 | } 14 | 15 | class PreBuildActionDescriptor extends Descriptor {} 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuildAction.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | // TODO for thesis text: 9 | // MAKE This interface instead of abstract class because when some classes will implement this, classes can extend multiple interface, but no multiple abstract classes 10 | public interface PostBuildAction extends ExtensionPoint, Describable, Action { 11 | default Descriptor getDescriptor() { 12 | return Jenkins.get().getDescriptor(getClass()); 13 | } 14 | 15 | class PostBuildActionDescriptor extends Descriptor {} 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuildAction.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.ExtensionPoint; 4 | import hudson.model.Describable; 5 | import hudson.model.Descriptor; 6 | import jenkins.model.Jenkins; 7 | 8 | // TODO for thesis text: 9 | // MAKE This interface instead of abstract class because when some classes will implement this, classes can extend multiple interface, but no multiple abstract classes 10 | public interface DuringBuildAction extends ExtensionPoint, Describable, Action { 11 | default Descriptor getDescriptor() { 12 | return Jenkins.get().getDescriptor(getClass()); 13 | } 14 | 15 | class DuringBuildActionDescriptor extends Descriptor {} 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/Reboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Reboot extends io.jenkins.plugins.agentManager.Actions.Reboot implements PostBuildAction { 10 | @DataBoundConstructor public Reboot() { 11 | super(); 12 | } 13 | 14 | @Extension 15 | @Symbol("Reboot") 16 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Reboot agent"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/Reboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Reboot extends io.jenkins.plugins.agentManager.Actions.Reboot implements DuringBuildAction { 10 | @DataBoundConstructor public Reboot() { 11 | super(); 12 | } 13 | 14 | @Extension 15 | @Symbol("Reboot") 16 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Reboot agent"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuild/Cleanup.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Cleanup extends io.jenkins.plugins.agentManager.Actions.Cleanup implements PreBuildAction { 10 | @DataBoundConstructor 11 | public Cleanup() { 12 | super(); 13 | } 14 | 15 | @Extension 16 | @Symbol("Cleanup") 17 | public static final class DescriptorImpl extends PreBuildActionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "Cleanup workspace"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuild/SetOffline.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class SetOffline extends io.jenkins.plugins.agentManager.Actions.SetOffline implements PreBuildAction { 10 | @DataBoundConstructor public SetOffline() { 11 | super(); 12 | } 13 | 14 | @Extension 15 | @Symbol("SetOffline") 16 | public static final class DescriptorImpl extends PreBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Take agent offline"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuild/StopBuild.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class StopBuild extends io.jenkins.plugins.agentManager.Actions.StopBuild implements PreBuildAction { 10 | @DataBoundConstructor public StopBuild() { 11 | super(); 12 | } 13 | 14 | 15 | @Extension 16 | @Symbol("StopBuild") 17 | public static final class DescriptorImpl extends PreBuildActionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "Stop build"; 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/StopBuild.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.TaskListener; 7 | 8 | import javax.servlet.ServletException; 9 | import java.io.IOException; 10 | 11 | public abstract class StopBuild implements Action { 12 | @Override 13 | public String getName() { 14 | return "StopBuild"; 15 | } 16 | 17 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild build, Computer computer) { 18 | try { 19 | build.doStop(); 20 | } catch (IOException e) { 21 | throw new RuntimeException(e); 22 | } catch (ServletException e) { 23 | throw new RuntimeException(e); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuild/Script.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Script extends io.jenkins.plugins.agentManager.Conditions.Script implements PreBuildCondition { 10 | @DataBoundConstructor public Script(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("Script") 16 | public static final class DescriptorImpl extends PreBuildConditionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Script output"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/Script.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Script extends io.jenkins.plugins.agentManager.Conditions.Script implements PostBuildCondition { 10 | @DataBoundConstructor public Script(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("Script") 16 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Script output"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/GracefulReboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class GracefulReboot extends io.jenkins.plugins.agentManager.Actions.GracefulReboot implements PostBuildAction { 10 | @DataBoundConstructor public GracefulReboot() { 11 | super(); 12 | } 13 | 14 | @Extension 15 | @Symbol("GracefulReboot") 16 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Gracefully reboot agent"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuild/NoCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class NoCondition extends io.jenkins.plugins.agentManager.Conditions.NoCondition implements PreBuildCondition { 10 | @DataBoundConstructor 11 | public NoCondition() { 12 | super(); 13 | } 14 | 15 | @Extension 16 | @Symbol("NoCondition") 17 | public static final class DescriptorImpl extends PreBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "No condition"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuild/GroovyScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class GroovyScript extends io.jenkins.plugins.agentManager.Actions.GroovyScript implements PreBuildAction { 10 | @DataBoundConstructor public GroovyScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("Groovy") 16 | public static final class DescriptorImpl extends PreBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom groovy script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PreBuild/ShellScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class ShellScript extends io.jenkins.plugins.agentManager.Actions.ShellScript implements PreBuildAction { 10 | @DataBoundConstructor public ShellScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("CustomScript") 16 | public static final class DescriptorImpl extends PreBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom shell script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuild/Script.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Script extends io.jenkins.plugins.agentManager.Conditions.Script implements DuringBuildCondition { 10 | @DataBoundConstructor public Script(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("Script") 16 | public static final class DescriptorImpl extends DuringBuildConditionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Script output"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/NoCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class NoCondition extends io.jenkins.plugins.agentManager.Conditions.NoCondition implements PostBuildCondition { 10 | @DataBoundConstructor 11 | public NoCondition() { 12 | super(); 13 | } 14 | 15 | @Extension 16 | @Symbol("NoCondition") 17 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "No condition"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/GracefulReboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class GracefulReboot extends io.jenkins.plugins.agentManager.Actions.GracefulReboot implements DuringBuildAction { 10 | @DataBoundConstructor public GracefulReboot() { 11 | super(); 12 | } 13 | 14 | @Extension 15 | @Symbol("GracefulReboot") 16 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Gracefully reboot agent"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/ShellScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class ShellScript extends io.jenkins.plugins.agentManager.Actions.ShellScript implements PostBuildAction { 10 | @DataBoundConstructor public ShellScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("ShellScript") 16 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom shell script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/GroovyScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class GroovyScript extends io.jenkins.plugins.agentManager.Actions.GroovyScript implements PostBuildAction { 10 | @DataBoundConstructor public GroovyScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("GroovyScript") 16 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom groovy script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/ShellScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class ShellScript extends io.jenkins.plugins.agentManager.Actions.ShellScript implements DuringBuildAction { 10 | @DataBoundConstructor public ShellScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("ShellScript") 16 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom shell script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/GroovyScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class GroovyScript extends io.jenkins.plugins.agentManager.Actions.GroovyScript implements DuringBuildAction { 10 | @DataBoundConstructor public GroovyScript(String scriptText) { 11 | super(scriptText); 12 | } 13 | 14 | @Extension 15 | @Symbol("GroovyScript") 16 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 17 | @NonNull 18 | @Override 19 | public String getDisplayName() { 20 | return "Run custom groovy script"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuild/NoCondition.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class NoCondition extends io.jenkins.plugins.agentManager.Conditions.NoCondition implements DuringBuildCondition { 10 | @DataBoundConstructor 11 | public NoCondition() { 12 | super(); 13 | } 14 | 15 | @Extension 16 | @Symbol("NoCondition") 17 | public static final class DescriptorImpl extends DuringBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "No condition (action runs everytime)"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/Cleanup.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Cleanup extends io.jenkins.plugins.agentManager.Actions.Cleanup implements PostBuildAction { 10 | @DataBoundConstructor 11 | public Cleanup() { 12 | super(); 13 | } 14 | 15 | @Override 16 | public String getName() { 17 | return "Cleanup"; 18 | } 19 | 20 | @Extension 21 | @Symbol("Cleanup") 22 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 23 | @NonNull 24 | @Override 25 | public String getDisplayName() { 26 | return "Cleanup workspace"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/StopBuild.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class StopBuild extends io.jenkins.plugins.agentManager.Actions.StopBuild implements PostBuildAction { 10 | @DataBoundConstructor public StopBuild() { 11 | super(); 12 | } 13 | 14 | @Override 15 | public String getName() { 16 | return "StopBuild"; 17 | } 18 | 19 | @Extension 20 | @Symbol("StopBuild") 21 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 22 | @NonNull 23 | @Override 24 | public String getDisplayName() { 25 | return "Stop build"; 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/HistoryTime.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class HistoryTime extends io.jenkins.plugins.agentManager.Conditions.HistoryTime implements PostBuildCondition { 10 | @DataBoundConstructor 11 | public HistoryTime(int quantity, long averageTime) { 12 | super(quantity, averageTime); 13 | } 14 | 15 | @Extension 16 | @Symbol("History") 17 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "Previous builds finish faster than"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/Cleanup.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Cleanup extends io.jenkins.plugins.agentManager.Actions.Cleanup implements DuringBuildAction { 10 | @DataBoundConstructor 11 | public Cleanup() { 12 | super(); 13 | } 14 | 15 | @Override 16 | public String getName() { 17 | return "Cleanup"; 18 | } 19 | 20 | @Extension 21 | @Symbol("Cleanup") 22 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 23 | @NonNull 24 | @Override 25 | public String getDisplayName() { 26 | return "Cleanup workspace"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/StopBuild.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class StopBuild extends io.jenkins.plugins.agentManager.Actions.StopBuild implements DuringBuildAction { 10 | @DataBoundConstructor public StopBuild() { 11 | super(); 12 | } 13 | 14 | @Override 15 | public String getName() { 16 | return "StopBuild"; 17 | } 18 | 19 | @Extension 20 | @Symbol("StopBuild") 21 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 22 | @NonNull 23 | @Override 24 | public String getDisplayName() { 25 | return "Stop build"; 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/PostBuild/SetOffline.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class SetOffline extends io.jenkins.plugins.agentManager.Actions.SetOffline implements PostBuildAction { 10 | @DataBoundConstructor public SetOffline() { 11 | super(); 12 | } 13 | 14 | @Override 15 | public String getName() { 16 | return "SetOffline"; 17 | } 18 | 19 | @Extension 20 | @Symbol("SetOffline") 21 | public static final class DescriptorImpl extends PostBuildActionDescriptor { 22 | @NonNull 23 | @Override 24 | public String getDisplayName() { 25 | return "Take agent offline"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuild/HistoryTime.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class HistoryTime extends io.jenkins.plugins.agentManager.Conditions.HistoryTime implements DuringBuildCondition { 10 | @DataBoundConstructor 11 | public HistoryTime(int quantity, long averageTime) { 12 | super(quantity, averageTime); 13 | } 14 | 15 | @Extension 16 | @Symbol("History") 17 | public static final class DescriptorImpl extends DuringBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "Previous builds finish faster than"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/DuringBuild/SetOffline.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class SetOffline extends io.jenkins.plugins.agentManager.Actions.SetOffline implements DuringBuildAction { 10 | @DataBoundConstructor public SetOffline() { 11 | super(); 12 | } 13 | 14 | @Override 15 | public String getName() { 16 | return "SetOffline"; 17 | } 18 | 19 | @Extension 20 | @Symbol("SetOffline") 21 | public static final class DescriptorImpl extends DuringBuildActionDescriptor { 22 | @NonNull 23 | @Override 24 | public String getDisplayName() { 25 | return "Take agent offline"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/BuildEntries/DuringBuildEntry/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuild/HistoryTime.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class HistoryTime extends io.jenkins.plugins.agentManager.Conditions.HistoryTime implements PreBuildCondition { 11 | @DataBoundConstructor 12 | public HistoryTime(int quantity, long averageTime) { 13 | super(quantity, averageTime); 14 | } 15 | 16 | @Extension 17 | @Symbol("History") 18 | public static final class DescriptorImpl extends PreBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Previous builds finish faster than"; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/Result.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 5 | import org.jenkinsci.Symbol; 6 | import org.kohsuke.stapler.DataBoundConstructor; 7 | import org.springframework.lang.NonNull; 8 | 9 | public class Result extends io.jenkins.plugins.agentManager.Conditions.Result implements PostBuildCondition { 10 | @DataBoundConstructor 11 | public Result(Boolean success, Boolean failure, Boolean aborted, Boolean unstable, Boolean notBuilt) { 12 | super(success, failure, aborted, unstable, notBuilt); 13 | } 14 | 15 | @Extension 16 | @Symbol("Result") 17 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 18 | @NonNull 19 | @Override 20 | public String getDisplayName() { 21 | return "Based on build result"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/TestHelper.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.slaves.DumbSlave; 5 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 6 | import org.jvnet.hudson.test.JenkinsRule; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | 12 | public class TestHelper { 13 | public static DumbSlave setupSlave(JenkinsRule jenkinsRule, List buildEntryList) throws Exception { 14 | NodePropertyImpl nodeProperty = new NodePropertyImpl(buildEntryList); 15 | 16 | DumbSlave slave = jenkinsRule.createSlave(); 17 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 18 | 19 | return slave; 20 | } 21 | 22 | public static FreeStyleProject setupProject(JenkinsRule jenkinsRule, DumbSlave slave) throws Exception { 23 | FreeStyleProject project = jenkinsRule.createFreeStyleProject(); 24 | project.setAssignedNode(slave); 25 | 26 | return project; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/ShellScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.TaskListener; 7 | import io.jenkins.plugins.agentManager.Utils.ShellScriptRunner; 8 | 9 | public abstract class ShellScript implements Action { 10 | private final String scriptText; 11 | private final String language; 12 | 13 | public ShellScript(String scriptText) { 14 | this.scriptText = scriptText; 15 | this.language = "BASH"; 16 | } 17 | 18 | public String getScriptText() { 19 | return scriptText; 20 | } 21 | 22 | public String getLanguage() { 23 | return language; 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return "CustomScript"; 29 | } 30 | 31 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild run, Computer computer) { 32 | ShellScriptRunner runner = new ShellScriptRunner(); 33 | 34 | String scriptContent = getScriptText(); 35 | runner.run(launcher, listener, scriptContent); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuild/DiskSpace.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class DiskSpace extends io.jenkins.plugins.agentManager.Conditions.DiskSpace implements PreBuildCondition { 11 | @DataBoundConstructor 12 | public DiskSpace(long space, String unit) { 13 | super(space, unit); 14 | } 15 | 16 | @Extension 17 | @Symbol("DiskSpace") 18 | public static final class DescriptorImpl extends PreBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Available space left"; 23 | } 24 | 25 | public ListBoxModel doFillUnitItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("MB"), 28 | new ListBoxModel.Option("GB") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Utils/Time.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Utils; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | public class Time { 6 | private static final String MILLISECONDS = "milliseconds"; 7 | private static final String SECONDS = "seconds"; 8 | private static final String MINUTES = "minutes"; 9 | 10 | public static String getMillisecondsString() { 11 | return MILLISECONDS; 12 | } 13 | 14 | public static String getSecondsString() { 15 | return SECONDS; 16 | } 17 | 18 | public static String getMinutesString() { 19 | return MINUTES; 20 | } 21 | 22 | public static long convertToMilliseconds(long time, String unit) { 23 | if (unit.equals(Time.getMillisecondsString())) 24 | return time; 25 | else if (unit.equals(Time.getSecondsString())) 26 | return TimeUnit.MILLISECONDS.convert(time, TimeUnit.SECONDS); 27 | else if (unit.equals(Time.getMinutesString())) 28 | return TimeUnit.MILLISECONDS.convert(time, TimeUnit.MINUTES); 29 | else 30 | // TODO add exception or error message 31 | return 0; 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/DiskSpace.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class DiskSpace extends io.jenkins.plugins.agentManager.Conditions.DiskSpace implements PostBuildCondition { 11 | @DataBoundConstructor 12 | public DiskSpace(long space, String unit) { 13 | super(space, unit); 14 | } 15 | 16 | @Extension 17 | @Symbol("DiskSpace") 18 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Available space left"; 23 | } 24 | 25 | public ListBoxModel doFillUnitItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("MB"), 28 | new ListBoxModel.Option("GB") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/Script.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.TaskListener; 6 | import io.jenkins.plugins.agentManager.Utils.ShellScriptRunner; 7 | 8 | public abstract class Script implements Condition { 9 | private final String scriptText; 10 | // TODO support groovy and windows thing 11 | private final String language; 12 | public Script(String scriptText) { 13 | this.scriptText = scriptText; 14 | this.language = "BASH"; 15 | } 16 | 17 | public String getScriptText() { 18 | return scriptText; 19 | } 20 | 21 | public String getLanguage() { 22 | return language; 23 | } 24 | 25 | @Override 26 | public String getName() { 27 | return "Script"; 28 | } 29 | 30 | @Override 31 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 32 | ShellScriptRunner runner = new ShellScriptRunner(); 33 | 34 | String scriptContent = getScriptText(); 35 | return runner.evaluateCondition(launcher, listener, scriptContent); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuild/DiskSpace.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class DiskSpace extends io.jenkins.plugins.agentManager.Conditions.DiskSpace implements DuringBuildCondition { 11 | @DataBoundConstructor 12 | public DiskSpace(long space, String unit) { 13 | super(space, unit); 14 | } 15 | 16 | @Extension 17 | @Symbol("DiskSpace") 18 | public static final class DescriptorImpl extends DuringBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Available space left"; 23 | } 24 | 25 | public ListBoxModel doFillUnitItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("MB"), 28 | new ListBoxModel.Option("GB") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/HistoryFailed.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class HistoryFailed extends io.jenkins.plugins.agentManager.Conditions.HistoryFailed implements PostBuildCondition { 11 | @DataBoundConstructor 12 | public HistoryFailed(int quantity) { 13 | super(quantity); 14 | } 15 | 16 | @Extension 17 | @Symbol("History") 18 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Previous builds failed"; 23 | } 24 | 25 | public ListBoxModel doFillHistoryConditionItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("Keep failing"), 28 | new ListBoxModel.Option("Finish too fast") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PreBuild/HistoryFailed.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PreBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class HistoryFailed extends io.jenkins.plugins.agentManager.Conditions.HistoryFailed implements PreBuildCondition { 11 | @DataBoundConstructor 12 | public HistoryFailed(int quantity) { 13 | super(quantity); 14 | } 15 | 16 | @Extension 17 | @Symbol("History") 18 | public static final class DescriptorImpl extends PreBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Previous builds failed"; 23 | } 24 | 25 | public ListBoxModel doFillHistoryConditionItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("Keep failing"), 28 | new ListBoxModel.Option("Finish too fast") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DuringBuild/HistoryFailed.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.DuringBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 6 | import org.jenkinsci.Symbol; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | import org.springframework.lang.NonNull; 9 | 10 | public class HistoryFailed extends io.jenkins.plugins.agentManager.Conditions.HistoryFailed implements DuringBuildCondition { 11 | @DataBoundConstructor 12 | public HistoryFailed(int quantity) { 13 | super(quantity); 14 | } 15 | 16 | @Extension 17 | @Symbol("History") 18 | public static final class DescriptorImpl extends DuringBuildConditionDescriptor { 19 | @NonNull 20 | @Override 21 | public String getDisplayName() { 22 | return "Previous builds failed"; 23 | } 24 | 25 | public ListBoxModel doFillHistoryConditionItems() { 26 | return new ListBoxModel( 27 | new ListBoxModel.Option("Keep failing"), 28 | new ListBoxModel.Option("Finish too fast") 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/GroovyScript.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.TaskListener; 7 | import io.jenkins.plugins.agentManager.Utils.GroovyScriptRunner; 8 | import io.jenkins.plugins.agentManager.Utils.ShellScriptRunner; 9 | 10 | public abstract class GroovyScript implements Action { 11 | private final String scriptText; 12 | // TODO support groovy and windows thing 13 | private final String language; 14 | 15 | public GroovyScript(String scriptText) { 16 | this.scriptText = scriptText; 17 | this.language = "BASH"; 18 | } 19 | 20 | public String getScriptText() { 21 | return scriptText; 22 | } 23 | 24 | public String getLanguage() { 25 | return language; 26 | } 27 | 28 | @Override 29 | public String getName() { 30 | return "CustomScript"; 31 | } 32 | 33 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild run, Computer computer) { 34 | GroovyScriptRunner runner = new GroovyScriptRunner(); 35 | 36 | String scriptContent = getScriptText(); 37 | runner.run(launcher, listener, scriptContent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Utils/ShellScriptRunner.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Utils; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.TaskListener; 5 | 6 | import java.io.IOException; 7 | 8 | public class ShellScriptRunner { 9 | public int executeScript(Launcher launcher, TaskListener listener, String scriptContent) throws IOException, InterruptedException { 10 | return launcher.launch().cmdAsSingleString(scriptContent).stdout(listener).join(); 11 | } 12 | 13 | public void run(Launcher launcher, TaskListener listener, String script) { 14 | try { 15 | executeScript(launcher, listener, script); 16 | } catch (IOException e) { 17 | // TODO e.printStackTrace(listener.fatalError()); 18 | throw new RuntimeException(e); 19 | } catch (InterruptedException e) { 20 | // TODO 21 | throw new RuntimeException(e); 22 | } 23 | } 24 | 25 | public boolean evaluateCondition(Launcher launcher, TaskListener listener, String scriptContent) { 26 | boolean condition = true; 27 | try { 28 | if (executeScript(launcher, listener, scriptContent) != 0) 29 | condition = false; 30 | } catch (IOException e) { 31 | // TODO 32 | condition = false; 33 | } catch (InterruptedException e) { 34 | // TODO 35 | condition = false; 36 | } 37 | 38 | return condition; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Utils/HelperActions.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Utils; 2 | 3 | import hudson.Launcher; 4 | import hudson.Messages; 5 | import hudson.model.*; 6 | import hudson.slaves.OfflineCause; 7 | import org.jvnet.localizer.ResourceBundleHolder; 8 | 9 | public class HelperActions { 10 | public static void rebootAgent(TaskListener listener, Launcher launcher, Computer computer) { 11 | ShellScriptRunner runner = new ShellScriptRunner(); 12 | 13 | String scriptContent; 14 | 15 | if (computer.isUnix()) 16 | scriptContent = "shutdown -r now"; 17 | else 18 | scriptContent = "shutdown -r -f -t 0"; 19 | 20 | runner.run(launcher, listener, scriptContent); 21 | } 22 | 23 | public static void setAgentOffline(TaskListener listener, Launcher launcher, AbstractBuild build, Computer computer) { 24 | // if (computer == null) 25 | // TODO 26 | 27 | ResourceBundleHolder holder = ResourceBundleHolder.get(Messages.class); 28 | User user = User.current(); 29 | int buildNumber = build.getNumber(); 30 | String buildName = build.getFullDisplayName(); 31 | String computerName = computer.getDisplayName(); 32 | String offlineMessage = String.format("Taking node '%s' offline temporarily. Triggered by build '%s' number '%d'", computerName, buildName, buildNumber); 33 | 34 | computer.setTemporarilyOffline(true, new OfflineCause.ByCLI(offlineMessage)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/io/jenkins/plugins/agentManager/NodePropertyImpl/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/HistoryFailed.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.Result; 7 | import hudson.model.Run; 8 | import hudson.model.TaskListener; 9 | import hudson.util.RunList; 10 | 11 | public abstract class HistoryFailed implements Condition { 12 | private final int quantity; 13 | 14 | public int getQuantity() { 15 | return quantity; 16 | } 17 | 18 | public HistoryFailed(int quantity) { 19 | this.quantity = quantity; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "HistoryFailed"; 25 | } 26 | 27 | @Override 28 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 29 | Computer computer = Computer.currentComputer(); 30 | RunList> runList = computer.getBuilds(); 31 | int quantity = getQuantity(); 32 | 33 | Run previousRun = runList.iterator().next(); 34 | for (int i = 0; i < quantity; i++) { 35 | // If there is not enough runs to evaluate condition, don't pass the condition 36 | if (previousRun == null) 37 | return false; 38 | 39 | // If some introspected builds didn't fail, condition doesn't pass 40 | if (!previousRun.getResult().equals(Result.FAILURE)) 41 | return false; 42 | 43 | previousRun = previousRun.getPreviousBuild(); 44 | } 45 | 46 | return true; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Utils/GroovyScriptRunner.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Utils; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.TaskListener; 5 | import hudson.util.RemotingDiagnostics; 6 | 7 | import java.io.IOException; 8 | 9 | public class GroovyScriptRunner { 10 | public String executeScript(Launcher launcher, TaskListener listener, String scriptContent) throws IOException, InterruptedException { 11 | return RemotingDiagnostics.executeGroovy(scriptContent, launcher.getChannel()); 12 | } 13 | 14 | public void run(Launcher launcher, TaskListener listener, String script) { 15 | try { 16 | String result = executeScript(launcher, listener, script); 17 | } catch (IOException e) { 18 | // TODO e.printStackTrace(listener.fatalError()); 19 | throw new RuntimeException(e); 20 | } catch (InterruptedException e) { 21 | // TODO 22 | throw new RuntimeException(e); 23 | } 24 | } 25 | 26 | public boolean evaluateCondition(Launcher launcher, TaskListener listener, String scriptContent) { 27 | boolean condition = true; 28 | try { 29 | String result = executeScript(launcher, listener, scriptContent); 30 | // TODO 31 | if (result == "whatistheresultofeexcutegroovy") 32 | condition = false; 33 | } catch (IOException e) { 34 | // TODO 35 | condition = false; 36 | } catch (InterruptedException e) { 37 | // TODO 38 | condition = false; 39 | } 40 | 41 | return condition; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/HistoryTime.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.Result; 5 | import hudson.model.*; 6 | import hudson.util.RunList; 7 | 8 | public abstract class HistoryTime implements Condition { 9 | private final int quantity; 10 | private final long averageTime; 11 | 12 | public int getQuantity() { 13 | return quantity; 14 | } 15 | 16 | public long getAverageTime() { 17 | return averageTime; 18 | } 19 | 20 | public HistoryTime(int quantity, long averageTime) { 21 | this.quantity = quantity; 22 | this.averageTime = averageTime; 23 | } 24 | 25 | @Override 26 | public String getName() { 27 | return "HistoryFailed"; 28 | } 29 | 30 | @Override 31 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 32 | Computer computer = Computer.currentComputer(); 33 | RunList> runList = computer.getBuilds(); 34 | int quantity = getQuantity(); 35 | 36 | Run previousRun = runList.iterator().next(); 37 | long currentAverage = 0; 38 | for (int i = 0; i < quantity; i++) { 39 | // If there is not enough runs to evaluate condition, don't pass the condition 40 | if (previousRun == null) 41 | return false; 42 | 43 | currentAverage += previousRun.getDuration(); 44 | previousRun = previousRun.getPreviousBuild(); 45 | } 46 | 47 | // Check 48 | return (currentAverage / quantity) < averageTime; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/NodePropertyImpl.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.Extension; 4 | import hudson.model.Node; 5 | import hudson.slaves.NodeProperty; 6 | import hudson.slaves.NodePropertyDescriptor; 7 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 8 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 9 | import org.jenkinsci.Symbol; 10 | import org.kohsuke.stapler.DataBoundConstructor; 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | public final class NodePropertyImpl extends NodeProperty { 16 | 17 | private final List entries; 18 | 19 | @DataBoundConstructor public NodePropertyImpl(List entries) { 20 | this.entries = entries != null ? new ArrayList(entries) : Collections.emptyList(); 21 | System.out.println(entries); 22 | System.out.println("Config"); 23 | System.out.println(entries.get(0) instanceof PostBuildEntry); 24 | } 25 | 26 | public List getEntries() { 27 | return Collections.unmodifiableList(entries); 28 | } 29 | 30 | @Extension @Symbol("actionNodeProperty") public static final class DescriptorImpl extends NodePropertyDescriptor { 31 | @Override 32 | public boolean isApplicable(Class nodeType) { 33 | return true; 34 | } 35 | 36 | // TODO do a form validation 37 | // TODO add a help 38 | 39 | @Override 40 | public String getDisplayName() { 41 | return "Configure build actions"; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/DiskSpace.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.ComputerSet; 7 | import hudson.model.TaskListener; 8 | import hudson.node_monitors.DiskSpaceMonitor; 9 | import hudson.node_monitors.DiskSpaceMonitorDescriptor; 10 | 11 | public abstract class DiskSpace implements Condition { 12 | private final long space; 13 | private final String unit; 14 | 15 | public long getSpace() { 16 | return space; 17 | } 18 | 19 | public String getUnit() { 20 | return unit; 21 | } 22 | 23 | public DiskSpace(long space, String unit) { 24 | this.space = space; 25 | this.unit = unit; 26 | } 27 | 28 | @Override 29 | public String getName() { 30 | return "DiskSpace"; 31 | } 32 | 33 | @Override 34 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 35 | long thresholdSpaceMB; 36 | if (getUnit().equals("GB")) 37 | thresholdSpaceMB = getSpace() * 1024; // make it MB 38 | else 39 | thresholdSpaceMB = getSpace(); 40 | 41 | // Move to some upper function and share this variable 42 | Computer computer = Computer.currentComputer(); 43 | DiskSpaceMonitor diskSpaceMonitor = ComputerSet.getMonitors().get(DiskSpaceMonitor.class); 44 | DiskSpaceMonitorDescriptor.DiskSpace freeSpace = diskSpaceMonitor.getFreeSpace(computer); 45 | long availableSpaceInMB = freeSpace.getFreeSize() * 1024 * 1024; 46 | 47 | return thresholdSpaceMB <= availableSpaceInMB; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/Duration.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.TaskListener; 6 | import io.jenkins.plugins.agentManager.Utils.Time; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | public abstract class Duration implements Condition { 11 | private final String durationCondition; 12 | private final long time; 13 | private final String unit; 14 | 15 | public String getDurationCondition() { 16 | return durationCondition; 17 | } 18 | 19 | public long getTime() { 20 | return time; 21 | } 22 | 23 | public String getUnit() { 24 | return unit; 25 | } 26 | 27 | public Duration(String durationCondition, long time, String unit) { 28 | this.durationCondition = durationCondition; 29 | this.time = time; 30 | this.unit = unit; 31 | } 32 | 33 | @Override 34 | public String getName() { 35 | return "Duration"; 36 | } 37 | 38 | @Override 39 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 40 | long buildDuration = run.getDuration(); 41 | String durationCondition = getDurationCondition(); 42 | String unit = getUnit(); 43 | long time = getTime(); 44 | long expectedDurationInMilliseconds = Time.convertToMilliseconds(time, unit); 45 | 46 | boolean returnVal; 47 | if (durationCondition.equals("Build took more than")) 48 | returnVal = buildDuration > expectedDurationInMilliseconds; 49 | else 50 | returnVal = buildDuration < expectedDurationInMilliseconds; 51 | 52 | return returnVal; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/PostBuild/Duration.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions.PostBuild; 2 | 3 | import hudson.Extension; 4 | import hudson.util.ListBoxModel; 5 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 6 | import io.jenkins.plugins.agentManager.Utils.Time; 7 | import org.jenkinsci.Symbol; 8 | import org.kohsuke.stapler.DataBoundConstructor; 9 | import org.springframework.lang.NonNull; 10 | 11 | public class Duration extends io.jenkins.plugins.agentManager.Conditions.Duration implements PostBuildCondition { 12 | @DataBoundConstructor 13 | public Duration(String durationCondition, long time, String unit) { 14 | super(durationCondition, time, unit); 15 | System.out.println("Duration PostBuildCondition:"); 16 | System.out.println(durationCondition); 17 | } 18 | 19 | @Extension 20 | @Symbol("Duration") 21 | public static final class DescriptorImpl extends PostBuildConditionDescriptor { 22 | @NonNull 23 | @Override 24 | public String getDisplayName() { 25 | return "Based on build duration"; 26 | } 27 | 28 | public ListBoxModel doFillUnitItems() { 29 | return new ListBoxModel( 30 | new ListBoxModel.Option(Time.getMillisecondsString()), 31 | new ListBoxModel.Option(Time.getSecondsString()), 32 | new ListBoxModel.Option(Time.getMinutesString()) 33 | ); 34 | } 35 | 36 | public ListBoxModel doFillDurationConditionItems() { 37 | return new ListBoxModel( 38 | new ListBoxModel.Option("Build took more than"), 39 | new ListBoxModel.Option("Build took less than") 40 | ); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ActionGracefulRebootTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.slaves.DumbSlave; 5 | import io.jenkins.plugins.agentManager.Actions.PostBuild.GracefulReboot; 6 | import io.jenkins.plugins.agentManager.Actions.PostBuild.Reboot; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 8 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 9 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.NoCondition; 10 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.jvnet.hudson.test.JenkinsRule; 14 | import org.jvnet.hudson.test.LoggerRule; 15 | 16 | import java.util.Arrays; 17 | import java.util.logging.Level; 18 | 19 | public class ActionGracefulRebootTest { 20 | @Rule 21 | public JenkinsRule jenkinsRule = new JenkinsRule(); 22 | @Rule 23 | public LoggerRule logger = new LoggerRule(); 24 | 25 | @Test 26 | public void testGracefulReboot() throws Exception { 27 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 28 | 29 | PostBuildCondition condition = new NoCondition(); 30 | PostBuildAction action = new GracefulReboot(); 31 | PostBuildEntry entry = new PostBuildEntry(condition, action); 32 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 33 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 34 | 35 | // TODO figure how how to run tests for reboot without actually rebooting the machine where the tests are running 36 | // jenkinsRule.buildAndAssertSuccess(freeStyleProject); 37 | // assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/PostBuildTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleBuild; 4 | import hudson.model.FreeStyleProject; 5 | import hudson.slaves.DumbSlave; 6 | import io.jenkins.plugins.agentManager.Actions.PostBuild.SetOffline; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 8 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 9 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 10 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.NoCondition; 11 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.jvnet.hudson.test.JenkinsRule; 15 | import org.jvnet.hudson.test.LoggerRule; 16 | 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.logging.Level; 20 | 21 | import static org.junit.Assert.assertTrue; 22 | 23 | public class PostBuildTest { 24 | @Rule 25 | public JenkinsRule jenkinsRule = new JenkinsRule(); 26 | @Rule 27 | public LoggerRule logger = new LoggerRule(); 28 | @Test 29 | public void testPostBuildEntries() throws Exception { 30 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 31 | 32 | PostBuildCondition postBuildCondition = new NoCondition(); 33 | PostBuildAction postBuildAction = new SetOffline(); 34 | PostBuildEntry postBuildEntry = new PostBuildEntry(postBuildCondition, postBuildAction); 35 | 36 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(postBuildEntry)); 37 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 38 | 39 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 40 | 41 | assertTrue(logger.getMessages().contains("Post-build actions completed")); 42 | jenkinsRule.assertBuildStatusSuccess(build); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ActionRebootTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.model.Result; 5 | import hudson.slaves.DumbSlave; 6 | import hudson.tasks.Shell; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuild.Reboot; 8 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 9 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 10 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 11 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.NoCondition; 12 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.jvnet.hudson.test.JenkinsRule; 16 | import org.jvnet.hudson.test.LoggerRule; 17 | 18 | import java.util.Arrays; 19 | import java.util.logging.Level; 20 | 21 | import static org.junit.Assert.assertTrue; 22 | 23 | public class ActionRebootTest { 24 | @Rule 25 | public JenkinsRule jenkinsRule = new JenkinsRule(); 26 | @Rule 27 | public LoggerRule logger = new LoggerRule(); 28 | 29 | @Test 30 | public void testReboot() throws Exception { 31 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 32 | 33 | PostBuildCondition condition = new NoCondition(); 34 | PostBuildAction action = new Reboot(); 35 | PostBuildEntry entry = new PostBuildEntry(condition, action); 36 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 37 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 38 | 39 | // TODO figure how how to run tests for reboot without actually rebooting the machine where the tests are running 40 | // jenkinsRule.buildAndAssertSuccess(freeStyleProject); 41 | // assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/GracefulReboot.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.Computer; 6 | import hudson.model.Run; 7 | import hudson.model.TaskListener; 8 | import io.jenkins.plugins.agentManager.Utils.HelperActions; 9 | 10 | public abstract class GracefulReboot implements Action { 11 | @Override 12 | public String getName() { 13 | return "GracefulReboot"; 14 | } 15 | 16 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild build, Computer computer) throws InterruptedException { 17 | HelperActions.setAgentOffline(listener, launcher, build, computer); 18 | 19 | 20 | // Wait for all builds on computer to finish 21 | // TODO prevent infinite time 22 | // TODO allow user to specify timeout for which it will wait for builds to finish 23 | for (Object object : computer.getBuilds()) { 24 | Run run = (Run) object; 25 | while (run.isBuilding()) { 26 | long estimatedRemaining = build.getExecutor().getEstimatedRemainingTimeMillis(); 27 | Thread.sleep(estimatedRemaining); 28 | } 29 | } 30 | 31 | HelperActions.rebootAgent(listener, launcher, computer); 32 | } 33 | /* private static void reboot(Launcher launcher, TaskListener listener, Run run, FilePath workspace) { 34 | OfflineCause cause = new OfflineCause(); 35 | 36 | computer.disconnect(OfflineCause.UserCause); 37 | 38 | Executable currentExecutable = computer.getExecutors().getCurrentExecutable(); 39 | if (currentExecutable != null) { 40 | QueueTaskFuture future = currentExecutable.getOwnerTask().getFuture(); 41 | if (future != null) { 42 | future.waitForCompletion(10, TimeUnit.SECONDS); 43 | } 44 | } 45 | } 46 | 47 | // Reconnect the computer 48 | if (computer != null) { 49 | computer.connect(false); 50 | } 51 | } */ 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/PreBuildTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.*; 4 | import hudson.slaves.DumbSlave; 5 | import io.jenkins.plugins.agentManager.Actions.PreBuild.SetOffline; 6 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 7 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 8 | import io.jenkins.plugins.agentManager.BuildEntries.PreBuildEntry; 9 | import io.jenkins.plugins.agentManager.Conditions.PreBuild.NoCondition; 10 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.jvnet.hudson.test.JenkinsRule; 14 | import org.jvnet.hudson.test.LoggerRule; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | import java.util.logging.Level; 19 | 20 | import static org.junit.Assert.assertTrue; 21 | 22 | public class PreBuildTest { 23 | @Rule 24 | public JenkinsRule jenkinsRule = new JenkinsRule(); 25 | @Rule 26 | public LoggerRule logger = new LoggerRule(); 27 | 28 | private FreeStyleProject setupProject(List buildEntryList) throws Exception { 29 | NodePropertyImpl nodeProperty = new NodePropertyImpl(buildEntryList); 30 | 31 | DumbSlave slave = jenkinsRule.createSlave(); 32 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 33 | 34 | FreeStyleProject project = jenkinsRule.createFreeStyleProject(); 35 | project.setAssignedNode(slave); 36 | 37 | return project; 38 | } 39 | 40 | @Test 41 | public void testPreBuildEntries() throws Exception { 42 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 43 | 44 | PreBuildCondition preBuildCondition = new NoCondition(); 45 | PreBuildAction preBuildAction = new SetOffline(); 46 | PreBuildEntry preBuildEntry = new PreBuildEntry(preBuildCondition, preBuildAction); 47 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(preBuildEntry)); 48 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 49 | 50 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 51 | 52 | assertTrue(logger.getMessages().contains("PreBuild actions completed")); 53 | jenkinsRule.assertBuildStatusSuccess(build); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Actions/Cleanup.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Actions; 2 | 3 | import hudson.FilePath; 4 | import hudson.Launcher; 5 | import hudson.model.AbstractBuild; 6 | import hudson.model.Computer; 7 | import hudson.model.TaskListener; 8 | 9 | import java.io.IOException; 10 | 11 | public abstract class Cleanup implements Action { 12 | @Override 13 | public String getName() { 14 | return "Cleanup"; 15 | } 16 | public void runAction(TaskListener listener, Launcher launcher, AbstractBuild run, Computer computer) { 17 | FilePath workspace = run.getWorkspace(); 18 | AbstractBuild build = run; 19 | 20 | try { 21 | workspace.deleteRecursive(); 22 | } catch (IOException e) { 23 | // TODO 24 | throw new RuntimeException(e); 25 | } catch (InterruptedException e) { 26 | // TODO 27 | throw new RuntimeException(e); 28 | } 29 | /* 30 | // TODO clean all the other finished workspaces 31 | Computer computer = Computer.currentComputer(); 32 | 33 | // computer.setTemporarilyOffline(true, new hudson.slaves.OfflineCause.ByCLI("disk cleanup")); 34 | Iterator runListIterator = computer.getBuilds().iterator(); 35 | Iterator runListIterator = computer.getBuilds(); 36 | 37 | while (runListIterator.hasNext()) { 38 | Run run = runListIterator.next(); 39 | 40 | if (run.isBuilding()) 41 | continue; 42 | 43 | // TODO check if workspace is in use 44 | 45 | workspacePath = node.getWorkspaceFor(item) 46 | if (workspacePath == null) { 47 | continue 48 | } 49 | customWorkspace = item.getCustomWorkspace() 50 | if (customWorkspace != null) { 51 | workspacePath = node.getRootPath().child(customWorkspace) 52 | } 53 | 54 | pathAsString = workspacePath.getRemote() 55 | if (workspacePath.exists()) { 56 | workspacePath.deleteRecursive() 57 | } else { 58 | } 59 | } 60 | 61 | computer.setTemporarilyOffline(false, null) 62 | */ 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionNoConditionTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.model.Result; 5 | import hudson.slaves.DumbSlave; 6 | import hudson.tasks.Shell; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 8 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 9 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 10 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.NoCondition; 11 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.jvnet.hudson.test.JenkinsRule; 15 | import org.jvnet.hudson.test.LoggerRule; 16 | 17 | import java.util.Arrays; 18 | import java.util.logging.Level; 19 | 20 | import static org.junit.Assert.assertTrue; 21 | 22 | public class ConditionNoConditionTest { 23 | @Rule 24 | public JenkinsRule jenkinsRule = new JenkinsRule(); 25 | @Rule 26 | public LoggerRule logger = new LoggerRule(); 27 | 28 | @Test 29 | public void testNoConditionWithSuccesBuild() throws Exception { 30 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 31 | 32 | // No condition is set, action should always run 33 | PostBuildCondition condition = new NoCondition(); // averageTime in milliseconnds 34 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 35 | PostBuildEntry entry = new PostBuildEntry(condition, action); 36 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 37 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 38 | 39 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 40 | 41 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 42 | } 43 | 44 | @Test 45 | public void testNoConditionWithFailedBuild() throws Exception { 46 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 47 | 48 | // No condition is set, action should always run 49 | PostBuildCondition condition = new NoCondition(); // averageTime in milliseconnds 50 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 51 | PostBuildEntry entry = new PostBuildEntry(condition, action); 52 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 53 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 54 | 55 | freeStyleProject.getBuildersList().add(new Shell("exit 1")); 56 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 57 | 58 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionDurationTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleBuild; 4 | import hudson.model.FreeStyleProject; 5 | import hudson.slaves.DumbSlave; 6 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 8 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 9 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.Duration; 10 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 11 | import io.jenkins.plugins.agentManager.Utils.Time; 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.jvnet.hudson.test.JenkinsRule; 15 | import org.jvnet.hudson.test.LoggerRule; 16 | 17 | import java.util.Arrays; 18 | import java.util.logging.Level; 19 | 20 | import static org.junit.Assert.assertTrue; 21 | 22 | public class ConditionDurationTest { 23 | @Rule 24 | public JenkinsRule jenkinsRule = new JenkinsRule(); 25 | @Rule 26 | public LoggerRule logger = new LoggerRule(); 27 | 28 | @Test 29 | public void testDurationPassed() throws Exception { 30 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 31 | 32 | PostBuildCondition condition = new Duration("Build took more than", 1, Time.getMillisecondsString()); 33 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 34 | PostBuildEntry entry = new PostBuildEntry(condition, action); 35 | 36 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 37 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 38 | 39 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 40 | 41 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 42 | jenkinsRule.assertBuildStatusSuccess(build); 43 | } 44 | 45 | @Test 46 | public void testDurationNotPassed() throws Exception { 47 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 48 | 49 | PostBuildCondition condition = new Duration("Build took less than", 1, Time.getMillisecondsString()); 50 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 51 | PostBuildEntry entry = new PostBuildEntry(condition, action); 52 | 53 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 54 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 55 | 56 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 57 | 58 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 59 | jenkinsRule.assertBuildStatusSuccess(build); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/BuildEntries/PreBuildEntry.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.BuildEntries; 2 | 3 | import hudson.DescriptorExtensionList; 4 | import hudson.Extension; 5 | import hudson.model.Descriptor; 6 | import io.jenkins.plugins.agentManager.Actions.Action; 7 | import io.jenkins.plugins.agentManager.Actions.PreBuildAction; 8 | import io.jenkins.plugins.agentManager.Conditions.PreBuildCondition; 9 | import io.jenkins.plugins.agentManager.Conditions.Condition; 10 | import jenkins.model.Jenkins; 11 | import org.jenkinsci.Symbol; 12 | import org.kohsuke.stapler.DataBoundConstructor; 13 | 14 | public class PreBuildEntry extends BuildEntry { 15 | /** 16 | * Override locations. Never null. 17 | */ 18 | private PreBuildCondition preBuildCondition; 19 | private PreBuildAction preBuildAction; 20 | 21 | @DataBoundConstructor 22 | public PreBuildEntry(PreBuildCondition preBuildCondition, PreBuildAction preBuildAction) { 23 | System.out.println("PreBuildActionInstance"); 24 | this.preBuildCondition = preBuildCondition; 25 | this.preBuildAction = preBuildAction; 26 | } 27 | 28 | @Extension 29 | @Symbol("preBuildEntry") 30 | public static class DescriptorImpl extends Descriptor { 31 | @Override public String getDisplayName() { 32 | return "Action run before build"; 33 | } 34 | } 35 | 36 | public PreBuildCondition getPreBuildCondition() { 37 | // Could return currently configured/saved item here to initialized form with this data 38 | return preBuildCondition; 39 | } 40 | 41 | public void setPreBuildCondition(PreBuildCondition preBuildCondition) { 42 | // Could return currently configured/saved item here to initialized form with this data 43 | this.preBuildCondition = preBuildCondition; 44 | } 45 | 46 | public PreBuildAction getPreBuildAction() { 47 | // Could return currently configured/saved item here to initialized form with this data 48 | return preBuildAction; 49 | } 50 | 51 | public void setPreBuildAction(PreBuildAction action) { 52 | // Could return currently configured/saved item here to initialized form with this data 53 | this.preBuildAction = action; 54 | } 55 | 56 | public Condition getCondition() { 57 | return this.preBuildCondition; 58 | } 59 | 60 | public Action getAction() { 61 | return this.preBuildAction; 62 | } 63 | 64 | public DescriptorExtensionList> getPreBuildConditionDescriptors() { 65 | return Jenkins.get().getDescriptorList(PreBuildCondition.class); 66 | } 67 | 68 | public DescriptorExtensionList> getPreBuildActionDescriptors() { 69 | return Jenkins.get().getDescriptorList(PreBuildAction.class); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/BuildEntries/PostBuildEntry.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.BuildEntries; 2 | 3 | import hudson.DescriptorExtensionList; 4 | import hudson.Extension; 5 | import hudson.model.Descriptor; 6 | import io.jenkins.plugins.agentManager.Actions.Action; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 8 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 9 | import io.jenkins.plugins.agentManager.Conditions.Condition; 10 | import jenkins.model.Jenkins; 11 | import org.jenkinsci.Symbol; 12 | import org.kohsuke.stapler.DataBoundConstructor; 13 | 14 | public class PostBuildEntry extends BuildEntry { 15 | /** 16 | * Override locations. Never null. 17 | */ 18 | private PostBuildCondition postBuildCondition; 19 | private PostBuildAction postBuildAction; 20 | 21 | @DataBoundConstructor 22 | public PostBuildEntry(PostBuildCondition postBuildCondition, PostBuildAction postBuildAction) { 23 | System.out.println("PostBuildActionInstance"); 24 | this.postBuildCondition = postBuildCondition; 25 | this.postBuildAction = postBuildAction; 26 | } 27 | 28 | @Extension 29 | @Symbol("postBuildActionInstance") 30 | public static class DescriptorImpl extends Descriptor { 31 | @Override public String getDisplayName() { 32 | return "Action run after build"; 33 | } 34 | } 35 | 36 | public PostBuildCondition getPostBuildCondition() { 37 | // Could return currently configured/saved item here to initialized form with this data 38 | return postBuildCondition; 39 | } 40 | 41 | public void setPostBuildCondition(PostBuildCondition postBuildCondition) { 42 | // Could return currently configured/saved item here to initialized form with this data 43 | this.postBuildCondition = postBuildCondition; 44 | } 45 | 46 | public PostBuildAction getPostBuildAction() { 47 | // Could return currently configured/saved item here to initialized form with this data 48 | return postBuildAction; 49 | } 50 | 51 | public void setPostBuildAction(PostBuildAction postBuildAction) { 52 | // Could return currently configured/saved item here to initialized form with this data 53 | this.postBuildAction = postBuildAction; 54 | } 55 | 56 | public Condition getCondition() { 57 | return this.postBuildCondition; 58 | } 59 | 60 | public Action getAction() { 61 | return this.postBuildAction; 62 | } 63 | 64 | public DescriptorExtensionList> getPostBuildConditionDescriptors() { 65 | return Jenkins.get().getDescriptorList(PostBuildCondition.class); 66 | } 67 | 68 | public DescriptorExtensionList> getPostBuildActionDescriptors() { 69 | return Jenkins.get().getDescriptorList(PostBuildAction.class); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/Conditions/Result.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.Conditions; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.AbstractBuild; 5 | import hudson.model.TaskListener; 6 | 7 | public abstract class Result implements Condition { 8 | private Boolean success; 9 | private Boolean failure; 10 | private Boolean aborted; 11 | private Boolean unstable; 12 | private Boolean notBuilt; 13 | 14 | public Result(Boolean success, Boolean failure, Boolean aborted, Boolean unstable, Boolean notBuilt) { 15 | this.success = success; 16 | this.failure = failure; 17 | this.aborted = aborted; 18 | this.unstable = unstable; 19 | this.notBuilt = notBuilt; 20 | } 21 | 22 | public Boolean getSuccess() { 23 | return success; 24 | } 25 | 26 | public void setSuccess(Boolean success) { 27 | this.success = success; 28 | } 29 | 30 | public Boolean getFailure() { 31 | return failure; 32 | } 33 | 34 | public void setFailure(Boolean failure) { 35 | this.failure = failure; 36 | } 37 | 38 | public Boolean getAborted() { 39 | return aborted; 40 | } 41 | 42 | public void setAborted(Boolean aborted) { 43 | this.aborted = aborted; 44 | } 45 | 46 | public Boolean getUnstable() { 47 | return unstable; 48 | } 49 | 50 | public void setUnstable(Boolean unstable) { 51 | this.unstable = unstable; 52 | } 53 | 54 | public Boolean getNotbuild() { 55 | return notBuilt; 56 | } 57 | 58 | public void setNotbuild(Boolean notBuilt) { 59 | this.notBuilt = notBuilt; 60 | } 61 | 62 | @Override 63 | public String getName() { 64 | return "Result"; 65 | } 66 | 67 | @Override 68 | public boolean conditionPasses(TaskListener listener, Launcher launcher, AbstractBuild run) { 69 | hudson.model.Result result = run.getResult(); 70 | 71 | // result is only set after all post-build actions have run, as post-build actions also may fail 72 | // so the result == null means that build has not encountered any error yet 73 | // if (result == null) { 74 | // return getScriptsByType("SUCCESS", listener); 75 | // } 76 | // Mentioned above doesn't fit anymore. That used to work only if we extend BuildWrapper or BuildStep. Extending BuildListener we have a meaningful output 77 | 78 | Boolean ret = false; 79 | if (getSuccess()) 80 | ret |= result == hudson.model.Result.SUCCESS; 81 | if (getFailure()) 82 | ret |= result == hudson.model.Result.FAILURE; 83 | if (getAborted()) 84 | ret |= result == hudson.model.Result.ABORTED; 85 | if (getUnstable()) 86 | ret |= result == hudson.model.Result.UNSTABLE; 87 | if (getNotbuild()) 88 | ret |= result == hudson.model.Result.NOT_BUILT; 89 | 90 | return ret; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionResultTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.model.Result; 5 | import hudson.slaves.DumbSlave; 6 | import hudson.tasks.Shell; 7 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 8 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 9 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 10 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.jvnet.hudson.test.JenkinsRule; 14 | import org.jvnet.hudson.test.LoggerRule; 15 | 16 | import java.util.Arrays; 17 | import java.util.logging.Level; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | public class ConditionResultTest { 22 | @Rule 23 | public JenkinsRule jenkinsRule = new JenkinsRule(); 24 | @Rule 25 | public LoggerRule logger = new LoggerRule(); 26 | 27 | @Test 28 | public void testResultWithSuccesBuild() throws Exception { 29 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 30 | 31 | // Expect build to succeed 32 | PostBuildCondition condition = new io.jenkins.plugins.agentManager.Conditions.PostBuild.Result(true, false, false, false, false); 33 | 34 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 35 | PostBuildEntry entry = new PostBuildEntry(condition, action); 36 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 37 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 38 | 39 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 40 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 41 | 42 | freeStyleProject.getBuildersList().add(new Shell("exit 1")); 43 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 44 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 45 | } 46 | 47 | @Test 48 | public void testResultWithFailedBuild() throws Exception { 49 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 50 | 51 | // Expect build to fail 52 | PostBuildCondition condition = new io.jenkins.plugins.agentManager.Conditions.PostBuild.Result(false, true, false, false, false); 53 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 54 | PostBuildEntry entry = new PostBuildEntry(condition, action); 55 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 56 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 57 | 58 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 59 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 60 | 61 | freeStyleProject.getBuildersList().add(new Shell("exit 1")); 62 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 63 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionScriptTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.slaves.DumbSlave; 5 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 6 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 7 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 8 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.Script; 9 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 10 | import org.junit.Rule; 11 | import org.junit.Test; 12 | import org.jvnet.hudson.test.JenkinsRule; 13 | import org.jvnet.hudson.test.LoggerRule; 14 | 15 | import java.util.Arrays; 16 | import java.util.logging.Level; 17 | 18 | import static org.junit.Assert.assertTrue; 19 | 20 | public class ConditionScriptTest { 21 | @Rule 22 | public JenkinsRule jenkinsRule = new JenkinsRule(); 23 | @Rule 24 | public LoggerRule logger = new LoggerRule(); 25 | 26 | @Test 27 | public void testScriptPass() throws Exception { 28 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 29 | 30 | // Spawn script which will return zero value (thus pass). A simple echo script will do fine 31 | PostBuildCondition condition = new Script("echo 'passing condition'"); 32 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 33 | PostBuildEntry entry = new PostBuildEntry(condition, action); 34 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 35 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 36 | 37 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 38 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 39 | } 40 | 41 | @Test 42 | public void testScriptFail() throws Exception { 43 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 44 | 45 | // Spawn script which will return non-zero value (thus fail) A simple script "false" will do fine 46 | PostBuildCondition condition = new Script("false"); 47 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 48 | PostBuildEntry entry = new PostBuildEntry(condition, action); 49 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 50 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 51 | 52 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 53 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 54 | } 55 | 56 | @Test 57 | public void testScriptMultiline() throws Exception { 58 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 59 | 60 | // Spawn script which will return non-zero value (thus fail) A simple script "false" will do fine 61 | PostBuildCondition condition = new Script("true;\ntrue;\nfalse"); 62 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 63 | PostBuildEntry entry = new PostBuildEntry(condition, action); 64 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 65 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 66 | 67 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 68 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/RunListenerImpl.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.Extension; 4 | import hudson.Launcher; 5 | import hudson.model.*; 6 | import hudson.model.listeners.RunListener; 7 | import jenkins.util.Timer; 8 | import org.kohsuke.stapler.DataBoundConstructor; 9 | import java.util.logging.Logger; 10 | import java.util.List; 11 | import java.util.concurrent.ScheduledExecutorService; 12 | import java.util.concurrent.ScheduledFuture; 13 | 14 | // The reason we want to use RunListener is that RunListener is not part of build as build-step, 15 | // which is more desired when running actions over agent which is usually some diagnostics, or system/server maintenance, which not being part of the build itself 16 | @Extension 17 | public class RunListenerImpl extends RunListener> { 18 | private static final Logger LOGGER = Logger.getLogger(RunListenerImpl.class.getName()); 19 | List> futureList; 20 | 21 | @DataBoundConstructor 22 | public RunListenerImpl() { 23 | // noop 24 | } 25 | 26 | @Override 27 | public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, BuildListener listener) { 28 | Computer currentComputer = Computer.currentComputer(); 29 | if (currentComputer == null) { 30 | LOGGER.severe("No Computer found. Cannot proceed with post-build action"); 31 | } 32 | 33 | ActionRunner actionRunner = new ActionRunner(launcher, listener, build); 34 | actionRunner.actPreBuild(currentComputer); 35 | LOGGER.info("PreBuild actions completed"); 36 | 37 | return new Environment() {}; 38 | } 39 | 40 | @Override 41 | public void onCompleted(Run run, TaskListener listener) { 42 | for (ScheduledFuture future : futureList) { 43 | future.cancel(true); 44 | } 45 | 46 | // TODO inverstigate when this can be null, especially on pipeline 47 | Computer currentComputer = Computer.currentComputer(); 48 | if (currentComputer == null) { 49 | LOGGER.severe("No Computer found. Cannot proceed with post-build action"); 50 | return; 51 | } 52 | 53 | Node node = currentComputer.getNode(); 54 | if (node == null) { 55 | LOGGER.severe("No Node found. Cannot proceed with post-build action"); 56 | return; 57 | } 58 | 59 | Launcher launcher = node.createLauncher(listener); 60 | AbstractBuild build = (AbstractBuild) run; 61 | 62 | ActionRunner actionRunner = new ActionRunner(launcher, listener, build); 63 | LOGGER.info("Triggering post-build actions"); 64 | actionRunner.actPostBuild(currentComputer); 65 | LOGGER.info("Post-build actions completed"); 66 | } 67 | 68 | @Override 69 | public void onStarted(Run run, TaskListener listener) { 70 | Computer currentComputer = Computer.currentComputer(); 71 | if (currentComputer == null) { 72 | LOGGER.severe("No Computer available. Cannot proceed with post-build action"); 73 | return; 74 | } 75 | Launcher launcher = currentComputer.getNode().createLauncher(listener); 76 | if (launcher == null) { 77 | LOGGER.severe("No launcher created. Cannot proceed with post-build action"); 78 | return; 79 | } 80 | AbstractBuild build = (AbstractBuild) run; 81 | 82 | ScheduledExecutorService executorService = Timer.get(); 83 | 84 | ActionRunner actionRunner = new ActionRunner(launcher, listener, build); 85 | this.futureList = actionRunner.actDuringBuild(executorService, Computer.currentComputer()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionHistoryFailedTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleBuild; 4 | import hudson.model.FreeStyleProject; 5 | import hudson.model.Result; 6 | import hudson.slaves.DumbSlave; 7 | import hudson.tasks.Shell; 8 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 9 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 10 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 11 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.HistoryFailed; 12 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.jvnet.hudson.test.JenkinsRule; 16 | import org.jvnet.hudson.test.LoggerRule; 17 | 18 | import java.util.Arrays; 19 | import java.util.logging.Level; 20 | 21 | import static org.junit.Assert.assertTrue; 22 | 23 | public class ConditionHistoryFailedTest { 24 | @Rule 25 | public JenkinsRule jenkinsRule = new JenkinsRule(); 26 | @Rule 27 | public LoggerRule logger = new LoggerRule(); 28 | 29 | @Test 30 | public void testHistoryFailedPassed() throws Exception { 31 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 32 | 33 | DumbSlave slave = jenkinsRule.createSlave(); 34 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 35 | freeStyleProject.getBuildersList().add(new Shell("exit 1")); 36 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 37 | 38 | PostBuildCondition condition = new HistoryFailed(2); 39 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 40 | PostBuildEntry entry = new PostBuildEntry(condition, action); 41 | NodePropertyImpl nodeProperty = new NodePropertyImpl(Arrays.asList(entry)); 42 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 43 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 44 | 45 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 46 | } 47 | 48 | @Test 49 | public void testHistoryFailedNotEnoughRuns() throws Exception { 50 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 51 | 52 | DumbSlave slave = jenkinsRule.createSlave(); 53 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 54 | freeStyleProject.getBuildersList().add(new Shell("exit 1")); 55 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 56 | 57 | // Try to check last 5 runs, but project has only 2 runs in history, so the condition should evaluate as false 58 | PostBuildCondition condition = new HistoryFailed(5); 59 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 60 | PostBuildEntry entry = new PostBuildEntry(condition, action); 61 | NodePropertyImpl nodeProperty = new NodePropertyImpl(Arrays.asList(entry)); 62 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 63 | jenkinsRule.buildAndAssertStatus(Result.FAILURE, freeStyleProject); 64 | 65 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 66 | } 67 | 68 | @Test 69 | public void testHistoryFailedNotPassed() throws Exception { 70 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 71 | 72 | PostBuildCondition condition = new HistoryFailed(1); 73 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 74 | PostBuildEntry entry = new PostBuildEntry(condition, action); 75 | 76 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(entry)); 77 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 78 | 79 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 80 | 81 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 82 | jenkinsRule.assertBuildStatusSuccess(build); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/ConditionHistoryTimeTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleProject; 4 | import hudson.slaves.DumbSlave; 5 | import io.jenkins.plugins.agentManager.Actions.PostBuild.ShellScript; 6 | import io.jenkins.plugins.agentManager.Actions.PostBuildAction; 7 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 8 | import io.jenkins.plugins.agentManager.Conditions.PostBuild.HistoryTime; 9 | import io.jenkins.plugins.agentManager.Conditions.PostBuildCondition; 10 | import org.junit.Rule; 11 | import org.junit.Test; 12 | import org.jvnet.hudson.test.JenkinsRule; 13 | import org.jvnet.hudson.test.LoggerRule; 14 | 15 | import java.util.Arrays; 16 | import java.util.logging.Level; 17 | 18 | import static org.junit.Assert.assertTrue; 19 | 20 | public class ConditionHistoryTimeTest { 21 | @Rule 22 | public JenkinsRule jenkinsRule = new JenkinsRule(); 23 | @Rule 24 | public LoggerRule logger = new LoggerRule(); 25 | 26 | @Test 27 | public void testHistoryTimePass() throws Exception { 28 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 29 | 30 | DumbSlave slave = jenkinsRule.createSlave(); 31 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 32 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 33 | 34 | // Set average time so high that every previous build will have lower build duration 35 | PostBuildCondition condition = new HistoryTime(2, 1000000); // averageTime in milliseconnds 36 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 37 | PostBuildEntry entry = new PostBuildEntry(condition, action); 38 | NodePropertyImpl nodeProperty = new NodePropertyImpl(Arrays.asList(entry)); 39 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 40 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 41 | 42 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as true", condition.getName()))); 43 | } 44 | 45 | @Test 46 | public void testHistoryTimeFail() throws Exception { 47 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 48 | 49 | DumbSlave slave = jenkinsRule.createSlave(); 50 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 51 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 52 | 53 | // Set average time so low that no previous build will have lower build duration 54 | PostBuildCondition condition = new HistoryTime(2, 1); // averageTime in milliseconnds 55 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 56 | PostBuildEntry entry = new PostBuildEntry(condition, action); 57 | NodePropertyImpl nodeProperty = new NodePropertyImpl(Arrays.asList(entry)); 58 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 59 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 60 | 61 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 62 | } 63 | 64 | @Test 65 | public void testHistoryTimeNotEnoughRuns() throws Exception { 66 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 67 | 68 | DumbSlave slave = jenkinsRule.createSlave(); 69 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 70 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 71 | 72 | // Try to check last 5 runs, but project has only 2 runs in history, so the condition should evaluate as false 73 | PostBuildCondition condition = new HistoryTime(5, 1); 74 | PostBuildAction action = new ShellScript("echo 'hello tests'"); 75 | PostBuildEntry entry = new PostBuildEntry(condition, action); 76 | NodePropertyImpl nodeProperty = new NodePropertyImpl(Arrays.asList(entry)); 77 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 78 | jenkinsRule.buildAndAssertSuccess(freeStyleProject); 79 | 80 | assertTrue(logger.getMessages().contains(String.format("Condition '%s' evaluated as false", condition.getName()))); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/io/jenkins/plugins/agentManager/DuringBuildTest.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.model.FreeStyleBuild; 4 | import hudson.model.FreeStyleProject; 5 | import hudson.slaves.DumbSlave; 6 | import io.jenkins.plugins.agentManager.Actions.DuringBuild.SetOffline; 7 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 8 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 9 | import io.jenkins.plugins.agentManager.BuildEntries.DuringBuildEntry; 10 | import io.jenkins.plugins.agentManager.Conditions.DuringBuild.NoCondition; 11 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 12 | import io.jenkins.plugins.agentManager.Utils.Time; 13 | import org.junit.Rule; 14 | import org.junit.Test; 15 | import org.jvnet.hudson.test.JenkinsRule; 16 | import org.jvnet.hudson.test.LoggerRule; 17 | 18 | import java.util.Arrays; 19 | import java.util.List; 20 | import java.util.logging.Level; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertTrue; 24 | 25 | public class DuringBuildTest { 26 | @Rule 27 | public JenkinsRule jenkinsRule = new JenkinsRule(); 28 | @Rule 29 | public LoggerRule logger = new LoggerRule(); 30 | 31 | private FreeStyleProject setupProject(List buildEntryList) throws Exception { 32 | NodePropertyImpl nodeProperty = new NodePropertyImpl(buildEntryList); 33 | 34 | DumbSlave slave = jenkinsRule.createSlave(); 35 | slave.setNodeProperties(Arrays.asList(nodeProperty)); 36 | 37 | FreeStyleProject project = jenkinsRule.createFreeStyleProject(); 38 | project.setAssignedNode(slave); 39 | 40 | return project; 41 | } 42 | 43 | @Test 44 | public void testDuringBuildEntriesInLoop() throws Exception { 45 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 46 | 47 | DuringBuildCondition duringBuildCondition = new NoCondition(); 48 | DuringBuildAction duringBuildAction = new SetOffline(); 49 | DuringBuildEntry duringBuildEntry = new DuringBuildEntry(1L, Time.getMillisecondsString(), true, duringBuildCondition, duringBuildAction); 50 | FreeStyleProject freeStyleProject = setupProject(Arrays.asList(duringBuildEntry)); 51 | 52 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 53 | 54 | // We set action to run in loop until the build finishes, so it should have been run more than once 55 | long countActionPerformed = 0; 56 | for (String message : logger.getMessages()) { 57 | if (message.equals(String.format("Performed action '%s' with condition '%s' during the build", duringBuildAction.getName(), duringBuildCondition.getName()))) { 58 | countActionPerformed++; 59 | } 60 | } 61 | 62 | assertTrue(countActionPerformed > 1); 63 | jenkinsRule.assertBuildStatusSuccess(build); 64 | } 65 | 66 | @Test 67 | public void testDuringBuildEntriesRunOnce() throws Exception { 68 | logger.capture(42).record(RunListenerImpl.class, Level.ALL); 69 | 70 | DuringBuildCondition duringBuildCondition = new NoCondition(); 71 | DuringBuildAction duringBuildAction = new SetOffline(); 72 | DuringBuildEntry duringBuildEntry = new DuringBuildEntry(1L, Time.getMillisecondsString(), false, duringBuildCondition, duringBuildAction); 73 | DumbSlave slave = TestHelper.setupSlave(jenkinsRule, Arrays.asList(duringBuildEntry)); 74 | FreeStyleProject freeStyleProject = TestHelper.setupProject(jenkinsRule, slave); 75 | 76 | FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(freeStyleProject); 77 | 78 | // We set action to run in loop until the build finishes, so it should have been run more than once 79 | long countActionPerformed = 0; 80 | for (String message : logger.getMessages()) { 81 | if (message.equals(String.format("Performed action '%s' with condition '%s' during the build", duringBuildAction.getName(), duringBuildCondition.getName()))) { 82 | countActionPerformed++; 83 | } 84 | } 85 | 86 | assertEquals(countActionPerformed, 1); 87 | jenkinsRule.assertBuildStatusSuccess(build); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/BuildEntries/DuringBuildEntry.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager.BuildEntries; 2 | 3 | import hudson.DescriptorExtensionList; 4 | import hudson.Extension; 5 | import hudson.model.Descriptor; 6 | import hudson.util.ListBoxModel; 7 | import io.jenkins.plugins.agentManager.Actions.Action; 8 | import io.jenkins.plugins.agentManager.Conditions.Condition; 9 | import io.jenkins.plugins.agentManager.Actions.DuringBuildAction; 10 | import io.jenkins.plugins.agentManager.Conditions.DuringBuildCondition; 11 | import io.jenkins.plugins.agentManager.Utils.Time; 12 | import jenkins.model.Jenkins; 13 | import org.jenkinsci.Symbol; 14 | import org.kohsuke.stapler.DataBoundConstructor; 15 | 16 | public class DuringBuildEntry extends BuildEntry { 17 | /** 18 | * Override locations. Never null. 19 | */ 20 | private DuringBuildCondition duringBuildCondition; 21 | private DuringBuildAction duringBuildAction; 22 | private Long time; 23 | private String unit; 24 | public Boolean loop; 25 | private Boolean actionPerformed; 26 | 27 | @DataBoundConstructor 28 | public DuringBuildEntry(Long time, String unit, boolean loop, DuringBuildCondition duringBuildCondition, DuringBuildAction duringBuildAction) { 29 | this.duringBuildCondition = duringBuildCondition; 30 | this.duringBuildAction = duringBuildAction; 31 | this.time = time; 32 | this.unit = unit; 33 | this.loop = loop; 34 | this.actionPerformed = false; 35 | } 36 | 37 | @Extension 38 | @Symbol("duringBuildActionInstance") 39 | public static class DescriptorImpl extends Descriptor { 40 | @Override public String getDisplayName() { 41 | return "Action run during build"; 42 | } 43 | 44 | public ListBoxModel doFillUnitItems() { 45 | return new ListBoxModel( 46 | new ListBoxModel.Option(Time.getMillisecondsString()), 47 | new ListBoxModel.Option(Time.getSecondsString()), 48 | new ListBoxModel.Option(Time.getMinutesString()) 49 | ); 50 | } 51 | } 52 | 53 | public DuringBuildCondition getDuringBuildCondition() { 54 | // Could return currently configured/saved item here to initialized form with this data 55 | return duringBuildCondition; 56 | } 57 | 58 | public void setDuringBuildCondition(DuringBuildCondition duringBuildCondition) { 59 | // Could return currently configured/saved item here to initialized form with this data 60 | this.duringBuildCondition = duringBuildCondition; 61 | } 62 | 63 | public DuringBuildAction getDuringBuildAction() { 64 | // Could return currently configured/saved item here to initialized form with this data 65 | return duringBuildAction; 66 | } 67 | 68 | public void setDuringBuildAction(DuringBuildAction duringBuildAction) { 69 | // Could return currently configured/saved item here to initialized form with this data 70 | this.duringBuildAction = duringBuildAction; 71 | } 72 | 73 | public Long getTime() { 74 | return time; 75 | } 76 | 77 | public void setTime(Long time) { 78 | this.time = time; 79 | } 80 | 81 | public String getUnit() { 82 | return unit; 83 | } 84 | 85 | public void setUnit(String unit) { 86 | this.unit = unit; 87 | } 88 | 89 | public Boolean getLoop() { 90 | return loop; 91 | } 92 | 93 | public void setLoop(Boolean loop) { 94 | this.loop = loop; 95 | } 96 | 97 | public Boolean getActionPerformed() { 98 | return actionPerformed; 99 | } 100 | 101 | public void setActionPerformed() { 102 | this.actionPerformed = true; 103 | } 104 | 105 | public Condition getCondition() { 106 | return this.duringBuildCondition; 107 | } 108 | 109 | public Action getAction() { 110 | return this.duringBuildAction; 111 | } 112 | 113 | public DescriptorExtensionList> getDuringBuildConditionDescriptors() { 114 | return Jenkins.get().getDescriptorList(DuringBuildCondition.class); 115 | } 116 | 117 | public DescriptorExtensionList> getDuringBuildActionDescriptors() { 118 | return Jenkins.get().getDescriptorList(DuringBuildAction.class); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.jenkins-ci.plugins 6 | plugin 7 | 4.41 8 | 9 | 10 | io.jenkins.plugins 11 | skobyda-agent-manager 12 | ${revision}${changelist} 13 | hpi 14 | TODO Plugin 15 | https://github.com/jenkinsci/${project.artifactId}-plugin 16 | 17 | 18 | MIT License 19 | https://opensource.org/licenses/MIT 20 | 21 | 22 | 30 | 31 | 32 | scm:git:https://github.com/${gitHubRepo} 33 | scm:git:https://github.com/${gitHubRepo} 34 | ${scmTag} 35 | https://github.com/${gitHubRepo} 36 | 37 | 1.0 38 | -SNAPSHOT 39 | 40 | 41 | 2.332.4 42 | jenkinsci/${project.artifactId}-plugin 43 | 44 | 45 | 46 | 47 | 48 | io.jenkins.tools.bom 49 | bom-2.332.x 50 | 1451.v15f1fdb_772a_f 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | org.jenkins-ci.plugins 59 | structs 60 | 61 | 62 | org.jenkins-ci.plugins.workflow 63 | workflow-cps 64 | test 65 | 66 | 67 | org.jenkins-ci.plugins.workflow 68 | workflow-job 69 | test 70 | 71 | 72 | org.jenkins-ci.plugins.workflow 73 | workflow-basic-steps 74 | test 75 | 76 | 77 | org.jenkins-ci.plugins.workflow 78 | workflow-durable-task-step 79 | test 80 | 81 | 82 | org.codehaus.groovy 83 | groovy-all 84 | 85 | 86 | org.mockito 87 | mockito-core 88 | 5.2.0 89 | test 90 | 91 | 92 | 93 | 94 | 95 | repo.jenkins-ci.org 96 | https://repo.jenkins-ci.org/public/ 97 | 98 | 99 | 100 | 101 | repo.jenkins-ci.org 102 | https://repo.jenkins-ci.org/public/ 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/main/java/io/jenkins/plugins/agentManager/ActionRunner.java: -------------------------------------------------------------------------------- 1 | package io.jenkins.plugins.agentManager; 2 | 3 | import hudson.Launcher; 4 | import hudson.model.*; 5 | import io.jenkins.plugins.agentManager.Actions.Action; 6 | import io.jenkins.plugins.agentManager.BuildEntries.BuildEntry; 7 | import io.jenkins.plugins.agentManager.BuildEntries.DuringBuildEntry; 8 | import io.jenkins.plugins.agentManager.BuildEntries.PostBuildEntry; 9 | import io.jenkins.plugins.agentManager.BuildEntries.PreBuildEntry; 10 | import io.jenkins.plugins.agentManager.Conditions.Condition; 11 | import io.jenkins.plugins.agentManager.Utils.Time; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.List; 16 | import java.util.concurrent.ScheduledExecutorService; 17 | import java.util.concurrent.ScheduledFuture; 18 | import java.util.concurrent.TimeUnit; 19 | import java.util.logging.Logger; 20 | 21 | public class ActionRunner { 22 | private static final Logger LOGGER = Logger.getLogger(RunListenerImpl.class.getName()); 23 | private final Launcher launcher; 24 | private final TaskListener listener; 25 | private final AbstractBuild build; 26 | 27 | public ActionRunner(Launcher launcher, TaskListener listener, AbstractBuild build) { 28 | this.launcher = launcher; 29 | this.listener = listener; 30 | this.build = build; 31 | } 32 | 33 | private List getEntriesPassingCondition(List entries) { 34 | List filtered = new ArrayList<>(); 35 | for (BuildEntry entry : entries) { 36 | Condition condition = entry.getCondition(); 37 | 38 | try { 39 | if (conditionPasses(condition)) 40 | filtered.add(entry); 41 | } catch (Exception e) { 42 | LOGGER.severe(String.format("Failed to evaluate condition %s", condition.getName())); 43 | } 44 | } 45 | 46 | // TODO we can get rid of filtering if entry had an "perform" method which runs an action when condition passes 47 | return filtered; 48 | } 49 | 50 | private List getEntriesByType(Class matchingClass) { 51 | List filtered = new ArrayList<>(); 52 | List entries = getAllNodeEntries(); 53 | 54 | for (BuildEntry entry : entries) { 55 | if (entry.getClass().equals(matchingClass)) { 56 | filtered.add(entry); 57 | } 58 | } 59 | 60 | return filtered; 61 | } 62 | 63 | private List getAllNodeEntries() { 64 | Node node = Computer.currentComputer().getNode(); 65 | NodePropertyImpl actionNodeProperty = node.getNodeProperties().get(NodePropertyImpl.class); 66 | 67 | if (actionNodeProperty == null) 68 | return Arrays.asList(); 69 | 70 | return actionNodeProperty.getEntries(); 71 | } 72 | 73 | private boolean conditionPasses(Condition condition) { 74 | boolean ret = false; 75 | try { 76 | ret = condition.conditionPasses(listener, launcher, build); 77 | LOGGER.info(String.format("Condition '%s' evaluated as %s", condition.getName(), ret)); 78 | } catch (Exception e) { 79 | LOGGER.severe(String.format("Failed to evaluate condition '%s': %s", condition.getName(), e.toString())); 80 | } 81 | 82 | return ret; 83 | } 84 | 85 | private void runAction(Action action, Computer computer) { 86 | try { 87 | action.runAction(listener, launcher, build, computer); 88 | LOGGER.info(String.format("Action '%s' finished successfully", action.getName())); 89 | } catch (Exception e) { 90 | LOGGER.severe(String.format("Failed to run action '%s': %s", action.getName(), e.toString())); 91 | } 92 | } 93 | 94 | private void act(List entries, Computer computer) { 95 | for (BuildEntry entry : entries) { 96 | Action action = entry.getAction(); 97 | 98 | runAction(action, computer); 99 | } 100 | } 101 | 102 | public void actPreBuild(Computer computer) { 103 | List entries = getEntriesByType(PreBuildEntry.class); 104 | List filteredEntries = getEntriesPassingCondition(entries); 105 | 106 | act(filteredEntries, computer); 107 | } 108 | 109 | public void actPostBuild(Computer computer) { 110 | List entries = getEntriesByType(PostBuildEntry.class); 111 | List filteredEntries = getEntriesPassingCondition(entries); 112 | 113 | act(filteredEntries, computer); 114 | } 115 | 116 | // Move this to a BuildEntry class 117 | private void evaluateAndRun(DuringBuildEntry entry, ScheduledExecutorService executorService, Computer computer) throws Exception { 118 | if (entry.getActionPerformed()) 119 | return; 120 | 121 | Condition condition = entry.getCondition(); 122 | if (conditionPasses(condition)) { 123 | Action action = entry.getAction(); 124 | runAction(action, computer); 125 | 126 | if (!entry.getLoop()) { 127 | // There is no way for us to cancel the Scheduled task from here. 128 | // So instead we set it so the action is not performed again 129 | // TODO 130 | // Alternatively we can also throw exception: 131 | // https://stackoverflow.com/questions/4909824/stop-a-periodic-task-from-within-the-task-itself-running-in-a-scheduledexecutors/4910682d 132 | entry.setActionPerformed(); 133 | } 134 | 135 | LOGGER.info(String.format("Performed action '%s' with condition '%s' during the build", action.getName(), condition.getName())); 136 | } 137 | } 138 | 139 | public List> actDuringBuild(ScheduledExecutorService executorService, Computer computer) { 140 | List entries = getEntriesByType(DuringBuildEntry.class); 141 | 142 | List > futureList = new ArrayList<>(); 143 | for (BuildEntry entry : entries) { 144 | DuringBuildEntry duringBuildEntry = (DuringBuildEntry) entry; 145 | 146 | long timeout = duringBuildEntry.getTime(); 147 | String timeoutUnit = duringBuildEntry.getUnit(); 148 | long timeoutInMillis = Time.convertToMilliseconds(timeout, timeoutUnit); 149 | 150 | Runnable periodicAction = () -> { 151 | try { 152 | evaluateAndRun(duringBuildEntry, executorService, computer); 153 | } catch (Exception e) { 154 | LOGGER.severe(String.format("Failed to run action %s with a condition %s", duringBuildEntry.getAction().getName(), duringBuildEntry.getCondition().getName())); 155 | } 156 | }; 157 | ScheduledFuture future = executorService.scheduleAtFixedRate(periodicAction, 0, timeoutInMillis, TimeUnit.MILLISECONDS); 158 | futureList.add(future); 159 | } 160 | 161 | return futureList; 162 | } 163 | } 164 | --------------------------------------------------------------------------------