diff --git a/core/src/main/java/hudson/cli/DeleteJobCommand.java b/core/src/main/java/hudson/cli/DeleteJobCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..2371023d263009e2892fa8b152e2f7b23b0cf1bc --- /dev/null +++ b/core/src/main/java/hudson/cli/DeleteJobCommand.java @@ -0,0 +1,92 @@ +/* + * The MIT License + * + * Copyright (c) 2015 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.cli; + +import hudson.Extension; +import hudson.model.AbstractItem; +import hudson.model.AbstractProject; +import hudson.model.View; +import hudson.model.ViewGroup; +import jenkins.model.Jenkins; +import org.kohsuke.args4j.Argument; + +import java.util.List; +import java.util.HashSet; + +/** + * @author pjanouse + * @since TODO + */ +@Extension +public class DeleteJobCommand extends CLICommand { + + @Argument(usage="Name of the job(s) to delete", required=true, multiValued=true) + private List jobs; + + @Override + public String getShortDescription() { + + return Messages.DeleteJobCommand_ShortDescription(); + } + + @Override + protected int run() throws Exception { + + boolean errorOccurred = false; + + HashSet hs = new HashSet(); + hs.addAll(jobs); + + for (String job_s: hs) { + AbstractItem job = (AbstractItem) Jenkins.getInstance().getItemByFullName(job_s); + + if(job == null) { + stderr.format("No such job '%s'\n", job_s); + errorOccurred = true; + continue; + } + + try { + job.checkPermission(AbstractItem.READ); + job.checkPermission(AbstractItem.DELETE); + } catch (Exception e) { + stderr.println(e.getMessage()); + errorOccurred = true; + continue; + } + + try { + job.delete(); + } catch (Exception e) { + stderr.format("Unexpected exception occurred during deletion of job '%s': %s\n", + job.getDisplayName(), + e.getMessage() + ); + errorOccurred = true; + continue; + } + } + return errorOccurred ? -1 : 0; + } +} diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 980da8ed44d4bc6c52cde64b7d71a44851bdb7a5..a5ab2409d4444a856fc7379a6f7ee2c5ae31c274 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -538,7 +538,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet * since it predates {@code }. {@code /delete} goes to a Jelly page * which should now be unused by core but is left in case plugins are still using it. */ - @CLIMethod(name="delete-job") +// @CLIMethod(name="delete-job") @RequirePOST public void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, InterruptedException { delete(); diff --git a/core/src/main/resources/hudson/cli/Messages.properties b/core/src/main/resources/hudson/cli/Messages.properties index 2713ac15a68f1f00f2a825e7d7e0235b6cd6f211..b942dfc91f4bebbad183def56dae3e319ca0558b 100644 --- a/core/src/main/resources/hudson/cli/Messages.properties +++ b/core/src/main/resources/hudson/cli/Messages.properties @@ -22,6 +22,8 @@ DeleteBuildsCommand.ShortDescription=\ Deletes build record(s). DeleteViewCommand.ShortDescription=\ Deletes view(s). +DeleteJobCommand.ShortDescription=\ + Deletes job(s). GroovyCommand.ShortDescription=\ Executes the specified Groovy script. GroovyshCommand.ShortDescription=\ diff --git a/core/src/main/resources/hudson/cli/Messages_da.properties b/core/src/main/resources/hudson/cli/Messages_da.properties index 05f432a523d2487c007322a520a8101f16ae960c..13079b94be6803f01833273d247853a6fbe54c55 100644 --- a/core/src/main/resources/hudson/cli/Messages_da.properties +++ b/core/src/main/resources/hudson/cli/Messages_da.properties @@ -1 +1,2 @@ DeleteNodeCommand.ShortDescription=Sletter en node +DeleteJobCommand.ShortDescription=Sletter et job diff --git a/core/src/main/resources/hudson/cli/Messages_de.properties b/core/src/main/resources/hudson/cli/Messages_de.properties index 3e0b589478216a0757bbdf10ae7a8674811e3961..21643e31c7ec2aaa42b761d8c24474f7d7e002f9 100644 --- a/core/src/main/resources/hudson/cli/Messages_de.properties +++ b/core/src/main/resources/hudson/cli/Messages_de.properties @@ -1 +1,2 @@ DeleteNodeCommand.ShortDescription=Knoten l\u00f6schen. +DeleteJobCommand.ShortDescription=Job l\u00f6schen. diff --git a/core/src/main/resources/hudson/cli/Messages_es.properties b/core/src/main/resources/hudson/cli/Messages_es.properties index 12bf0a59e3e1f8df6478214075e9af0907dcd079..4703a13dd97dbeca9b69b14aecfa3abec3796013 100644 --- a/core/src/main/resources/hudson/cli/Messages_es.properties +++ b/core/src/main/resources/hudson/cli/Messages_es.properties @@ -47,5 +47,6 @@ WhoAmICommand.ShortDescription=Muestra tus credenciales y permisos UpdateJobCommand.ShortDescription=Actualiza el fichero XML de la definición de una tarea desde la entrada estándard. Es lo contrario al comando get-job. GroovyshCommand.ShortDescription=Ejecuta una shell interactiva de groovy. SetBuildDescriptionCommand.ShortDescription=Establece la descripción de una ejecución. +DeleteJobCommand.ShortDescription=Borrar una tarea DeleteNodeCommand.ShortDescription=Borrar un nodo diff --git a/core/src/main/resources/hudson/cli/Messages_it.properties b/core/src/main/resources/hudson/cli/Messages_it.properties index fd75db7ef48d8cb8775182afb625a0a8e1c07371..6a79e3ab9d5b2c0627cae44e3c36ab2221d865b3 100644 --- a/core/src/main/resources/hudson/cli/Messages_it.properties +++ b/core/src/main/resources/hudson/cli/Messages_it.properties @@ -1 +1,2 @@ DeleteNodeCommand.ShortDescription=Cancella un nodo +DeleteJobCommand.ShortDescription=Cancella un job diff --git a/core/src/main/resources/hudson/cli/Messages_ja.properties b/core/src/main/resources/hudson/cli/Messages_ja.properties index f13882e426f24c35f668a1236982db1a97d6ab27..a6cdca19f468bc002fc7bfbdf173deba6046f31b 100644 --- a/core/src/main/resources/hudson/cli/Messages_ja.properties +++ b/core/src/main/resources/hudson/cli/Messages_ja.properties @@ -71,3 +71,4 @@ BuildCommand.CLICause.CannotBuildUnknownReasons=\ \u30d3\u30eb\u30c9\u3067\u304d\u307e\u305b\u3093(\u539f\u56e0\u4e0d\u660e)\u3002 DeleteNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3092\u524a\u9664\u3057\u307e\u3059\u3002 +DeleteJobCommand.ShortDescription=\u30b8\u30e7\u30d6\u3092\u524a\u9664\u3057\u307e\u3059\u3002 diff --git a/core/src/main/resources/hudson/cli/Messages_pt_BR.properties b/core/src/main/resources/hudson/cli/Messages_pt_BR.properties index f120c36022501f6443010b8f3137712feb4903c1..06cc84d38800b009f28d03382db0ade07afd1648 100644 --- a/core/src/main/resources/hudson/cli/Messages_pt_BR.properties +++ b/core/src/main/resources/hudson/cli/Messages_pt_BR.properties @@ -113,3 +113,5 @@ InstallPluginCommand.ShortDescription=Instala um plugin a partir de um arquivo, # Deletes a node CLI.delete-node.shortDescription=Remover o n\u00f3 +# Deletes a job +DeleteJobCommand.ShortDescription=Remover uma job diff --git a/core/src/main/resources/hudson/cli/Messages_zh_CN.properties b/core/src/main/resources/hudson/cli/Messages_zh_CN.properties index 8011124de84228f614acf6530589e3206c203b4f..62e09b76124e6f7d9c29c2990c4826288b6e536c 100644 --- a/core/src/main/resources/hudson/cli/Messages_zh_CN.properties +++ b/core/src/main/resources/hudson/cli/Messages_zh_CN.properties @@ -1 +1,2 @@ DeleteNodeCommand.ShortDescription=Deletes a node +DeleteJobCommand.ShortDescription=Deletes a job diff --git a/core/src/main/resources/hudson/cli/Messages_zh_TW.properties b/core/src/main/resources/hudson/cli/Messages_zh_TW.properties index 5953f6537c2f20cdb2b38f98f2f89aa2303404d4..7921933ce69354c5c064dd08faf88f688979fa7d 100644 --- a/core/src/main/resources/hudson/cli/Messages_zh_TW.properties +++ b/core/src/main/resources/hudson/cli/Messages_zh_TW.properties @@ -74,3 +74,4 @@ UpdateJobCommand.ShortDescription=\ BuildCommand.CLICause.ShortDescription=\u7531 {0} \u7684\u547d\u4ee4\u5217\u4ecb\u9762\u555f\u52d5 DeleteNodeCommand.ShortDescription=\u522a\u9664\u6307\u5b9a\u7bc0\u9ede\u3002 +DeleteJobCommand.ShortDescription=\u522a\u9664\u4f5c\u696d\u3002 diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 110409b09b172548dfe9499cb829cc8383b0c90a..29c95e79079d3fd4b69db727df1228c52a253408 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -93,7 +93,6 @@ BallColor.Success=Success BallColor.Unstable=Unstable CLI.clear-queue.shortDescription=Clears the build queue. -CLI.delete-job.shortDescription=Deletes a job. CLI.reload-job.shortDescription=Reloads this job from disk. CLI.disable-job.shortDescription=Disables a job. CLI.enable-job.shortDescription=Enables a job. diff --git a/core/src/main/resources/hudson/model/Messages_da.properties b/core/src/main/resources/hudson/model/Messages_da.properties index b5b4c9ed7a847eedb0934f8200922977e82e9cf4..3300fc73881c0c22d4c093906b8c114f7c5117b4 100644 --- a/core/src/main/resources/hudson/model/Messages_da.properties +++ b/core/src/main/resources/hudson/model/Messages_da.properties @@ -82,7 +82,6 @@ UpdateCenter.PluginCategory.cli=Kommandolinieinterface UpdateCenter.PluginCategory.builder=Byggev\u00e6rkt\u00f8jer Slave.UnixSlave=Dette er en Unix slave FileParameterDefinition.DisplayName=Filparametre -CLI.delete-job.shortDescription=Sletter et job Run.Summary.Unstable=Ustabil CLI.reload-configuration.shortDescription=Genindl\u00e6s alle data fra filsystemet. \ Nyttigt hvis du har modificeret konfigurationsfiler direkte, udenom Jenkins. diff --git a/core/src/main/resources/hudson/model/Messages_de.properties b/core/src/main/resources/hudson/model/Messages_de.properties index 8da9942ec767b0224fdd0280a951c2aeeffaab4a..5c3b3459096bf16f5f6a43cae7517a860ecf286c 100644 --- a/core/src/main/resources/hudson/model/Messages_de.properties +++ b/core/src/main/resources/hudson/model/Messages_de.properties @@ -83,7 +83,6 @@ CLI.quiet-down.shortDescription=Jenkins' Aktivit\u00e4t reduzieren, z.B. zur Vor CLI.cancel-quiet-down.shortDescription=Wirkung des Befehls "quiet-down" wieder aufheben. CLI.reload-configuration.shortDescription=Alle Daten im Speicher verwerfen und Konfiguration neu von Festplatte laden. Dies ist n\u00fctzlich, wenn Sie \u00c4nderungen direkt im Dateisystem vorgenommen haben. CLI.clear-queue.shortDescription=Build-Warteschlange l\u00f6schen. -CLI.delete-job.shortDescription=Job l\u00f6schen. CLI.disable-job.shortDescription=Job deaktivieren. CLI.enable-job.shortDescription=Job aktivieren. CLI.connect-node.shortDescription=Erneut mit Knoten verbinden. diff --git a/core/src/main/resources/hudson/model/Messages_es.properties b/core/src/main/resources/hudson/model/Messages_es.properties index 2e20c2495d2a300996d5ffb7a4ce91addf3d497a..27eb91abc85fed0d40f9eb483bfbf3c028ee2559 100644 --- a/core/src/main/resources/hudson/model/Messages_es.properties +++ b/core/src/main/resources/hudson/model/Messages_es.properties @@ -59,7 +59,6 @@ BallColor.Success=Correcto BallColor.Unstable=Inestable CLI.clear-queue.shortDescription=Limpiar la cola de trabajos -CLI.delete-job.shortDescription=Borrar una tarea CLI.disable-job.shortDescription=Desactivar una tarea CLI.enable-job.shortDescription=Activar una tarea CLI.disconnect-node.shortDescription=Desconectarse de un nodo diff --git a/core/src/main/resources/hudson/model/Messages_it.properties b/core/src/main/resources/hudson/model/Messages_it.properties index 905f2beaa6c3c1171c61f2bb8497844dda02bf3a..fd106bf53b61e5b1b173f9c33cf723275597719f 100644 --- a/core/src/main/resources/hudson/model/Messages_it.properties +++ b/core/src/main/resources/hudson/model/Messages_it.properties @@ -77,7 +77,6 @@ BallColor.Success=Successo BallColor.Unstable=Instabile CLI.clear-queue.shortDescription=Pulisce la coda di lavoro -CLI.delete-job.shortDescription=Cancella un job CLI.disable-job.shortDescription=Disabilita un job CLI.enable-job.shortDescription=Abilita un job CLI.disconnect-node.shortDescription=Disconnects from a node diff --git a/core/src/main/resources/hudson/model/Messages_ja.properties b/core/src/main/resources/hudson/model/Messages_ja.properties index 088506a5b88bff48d172a851bbfbaadcd15294a8..6d31b46cf5c6c21fde28dd519ddf57b46d926abb 100644 --- a/core/src/main/resources/hudson/model/Messages_ja.properties +++ b/core/src/main/resources/hudson/model/Messages_ja.properties @@ -320,7 +320,6 @@ CLI.quiet-down.shortDescription=Jenkins\u306f\u518d\u8d77\u52d5\u306b\u5411\u305 CLI.cancel-quiet-down.shortDescription="quite-down"\u30b3\u30de\u30f3\u30c9\u306e\u51e6\u7406\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u307e\u3059\u3002 CLI.reload-configuration.shortDescription=\u30e1\u30e2\u30ea\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u3092\u7834\u68c4\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u518d\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u76f4\u63a5\u4fee\u6b63\u3057\u305f\u5834\u5408\u306b\u5f79\u306b\u7acb\u3061\u307e\u3059\u3002 CLI.clear-queue.shortDescription=\u30d3\u30eb\u30c9\u30ad\u30e5\u30fc\u3092\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002 -CLI.delete-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u524a\u9664\u3057\u307e\u3059\u3002 CLI.disable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u7121\u52b9\u5316\u3057\u307e\u3059\u3002 CLI.enable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u6709\u52b9\u5316\u3057\u307e\u3059\u3002 CLI.disconnect-node.shortDescription=\u30ce\u30fc\u30c9\u3068\u306e\u63a5\u7d9a\u3092\u5207\u65ad\u3057\u307e\u3059\u3002 diff --git a/core/src/main/resources/hudson/model/Messages_pt_BR.properties b/core/src/main/resources/hudson/model/Messages_pt_BR.properties index 770d0ab6d2cd0d4b43349c04c3e0528a28039ca2..663c87f330a7b45b82d80e3dca98cbdce8f4cbf2 100644 --- a/core/src/main/resources/hudson/model/Messages_pt_BR.properties +++ b/core/src/main/resources/hudson/model/Messages_pt_BR.properties @@ -187,8 +187,6 @@ UpdateCenter.PluginCategory.builder=Ferramentas de build # File Parameter FileParameterDefinition.DisplayName=Par\u00e2metros de arquivo # {0} {0,choice,0#tests are|1#test is|1