bmuschko/gradle-cargo-plugin

undeploy-like tasks dependencies

jeusdi opened this issue · 7 comments

I'm facing up how to deal with my undeployDev-like tasks.

This is my configuration:

remoteContainers.each { config ->
	task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
      	description = "Deploys WAR to remote Web Application Server: '${config.name}'."
       	containerId = config.container
       	hostname = config.hostname
	port = config.port
       	username = config.username
        password = config.password
        dependsOn = [createDevelopmentWar]
	deployables = [new com.bmuschko.gradle.cargo.convention.Deployable(file: createDevelopmentWar.archivePath, context: 'commty')]
    }
}

As you can see on my undeployDev-like task, it depends on another task createDevelopmentWar. So I don't want each time I need to undeploy the artifact, it needs to regenerate the deployable. I'd like to set which context the task need to undeploy without any other dependency.

I've took a look on documentation, nevertheless, I don't quite figure what would I need to do...

I don't think you need to necessarily create the underlying artifact deployable to undeploy. You can probably just set the context property.

I've tried this:

task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
      	description = "Deploys WAR to remote Web Application Server: '${config.name}'."
       	containerId = config.container
       	hostname = config.hostname
	port = config.port
       	username = config.username
        password = config.password
	deployables = [new com.bmuschko.gradle.cargo.convention.Deployable(context: 'commty')]

Nevertheless, I'm getting this error message:

* What went wrong:
Execution failed for task ':undeployDevWildfly10'.
> Cannot invoke method exists() on null object

I've also tried this:

task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
      	description = "Deploys WAR to remote Web Application Server: '${config.name}'."
       	containerId = config.container
       	hostname = config.hostname
	port = config.port
       	username = config.username
        password = config.password
        context = 'commty'
    }

I'm getting this exception message:

* What went wrong:
Execution failed for task ':undeployDevWildfly10'.
> File 'D:\projects\living\platform\commty\build\libs\commty-dev-351f5f0-dirty.war' does not exist

My war task is defined as:

war {
    archiveName "commty-${versioning.info.display}.war"
    webInf { from 'src/main/resources/WEB-INF' }
    manifest {
	attributes 'Implementation-Version': versioning.info.display
    }
}

Cannot invoke method exists() on null object

Can you provide a stack trace? If that checks the existence of the Deployable.file then it is a bug.

This is the --stacktrace output:

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':undeployDevWildfly10'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:74)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:55)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:153)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:82)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:59)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:49)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.HintGCAfterBuild.execute(HintGCAfterBuild.java:44)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:240)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.IllegalArgumentException: File 'D:\projects\living\platform\commty\build\libs\commty-dev-8598fb9-dirty.war' does not exist
        at com.bmuschko.gradle.cargo.util.DefaultFileUtil.getExtension(DefaultFileUtil.groovy:25)
        at com.bmuschko.gradle.cargo.util.FileUtil$getExtension.call(Unknown Source)
        at com.bmuschko.gradle.cargo.DeployableTypeFactory.getType(DeployableTypeFactory.groovy:12)
        at com.bmuschko.gradle.cargo.DeployableTypeFactory$getType.call(Unknown Source)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask$_runAction_closure2$_closure4$_closure5.doCall(RemoteCargoContainerTask.groovy:94)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask$_runAction_closure2$_closure4.doCall(RemoteCargoContainerTask.groovy:93)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask$_runAction_closure2$_closure4.doCall(RemoteCargoContainerTask.groovy)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:103)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask$_runAction_closure2.doCall(RemoteCargoContainerTask.groovy:82)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask$_runAction_closure2.doCall(RemoteCargoContainerTask.groovy)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:103)
        at com.bmuschko.gradle.cargo.tasks.remote.RemoteCargoContainerTask.runAction(RemoteCargoContainerTask.groovy:81)
        at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask$_start_closure2.doCall(AbstractCargoContainerTask.groovy:92)
        at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask$_start_closure2.doCall(AbstractCargoContainerTask.groovy)
        at com.bmuschko.gradle.cargo.util.LoggingHandler.withAntLoggingListener(LoggingHandler.groovy:36)
        at com.bmuschko.gradle.cargo.util.LoggingHandler$withAntLoggingListener.call(Unknown Source)
        at com.bmuschko.gradle.cargo.tasks.AbstractCargoContainerTask.start(AbstractCargoContainerTask.groovy:91)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:133)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:126)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:115)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:623)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:606)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 68 more

And this is the task configuration:

task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
      	description = "Deploys WAR to remote Web Application Server: '${config.name}'."
       	containerId = config.container
       	hostname = config.hostname
		port = config.port
       	username = config.username
        password = config.password
        context = 'commty'
    }

@bmuschko have you been able to get something...?

Hi,

Facing the same issue with CargoUndeployRemote. For some reason it needs the exact war file name that's deployed on Tomcat. According to Tomcat documentation here:

https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Undeploy_an_Existing_Application

That should not be required as the manager API only needs the action name (undeploy) and the context ('/', '/exeamples', etc.).

Here is the error message:

org.codehaus.cargo.container.ContainerException: Deployable [/ol-1.0.118] is not deployed

For us knowing the exact war file name will not be possible anyway as the build process adds a suffix to the war file name indicating the Jenkins build number and the deployable is always built before the deployment task. Since builds do fail (sometimes) the indexes will be a bit out of sequence in those cases (i.e. 112, 113, 118 (because 5 builds failed in a row)).

Here is my gradle script doing the undeploy.

class RemoteContainer {
String name
String hostname
Integer port
String username
String password
String context
}

def remoteContainers = [new RemoteContainer(name: 'devtest', hostname: 'testhost',
port: 8080, username: 'tomcat', password: 'tomcat', context: '/')]

remoteContainers.each { config ->
task "unDeploy${config.name.capitalize()}"(type: SafeUndeployRemote) {
description = "Un-deploys a WAR from remote Tomcat '${config.name}'."
containerId = 'tomcat7x'
hostname = config.hostname
port = config.port
username = config.username
password = config.password
context = config.context
}
}

class SafeUndeployRemote extends com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote {

@Override
void runAction() {
	try {
		super.runAction()
	} catch (e) { println "undeploy failed: $e.message"}
}

}

Any help regarding this would be much appreciated. Been stuck on this now for a while and would ideally like to keep things in Gradle (I know it can get it done with curl).