How to get an AnyTrigger to compile
Asked by jzajac2:

I am writing PlanSpec.java for a build plan I have which contains After Deployment Triggers, however I cannot get it to compile. Here is a relevant portion of the code, apologies for the poor formatting:  

<br />

```
  new AfterDeploymentTrigger()
     .description("After test Prod Environment Deployment")
     .deploymentProject("test")
     .environment("prod")
*/
new AnyTrigger(new AtlassianModule("com.atlassianlab.bamboo.plugins.bamboo-after-deployment-trigger-plugin:afterDeployment"))
  .name("After deployment")
  .description("After test Prod Environment Deployment")
  .configuration(new MapBuilder()
  .put("deployment.trigger.afterDeployment.deploymentProjectId", "449904641")
  .put("deployment.trigger.afterDeployment.deploymentEnvironmentId", "449118216")
  .build()),
```

<br />

The compile error is:  

```
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project attcs-bamboo-plans: Compilation failure: Compilation failure: 
[ERROR] /bamboo-specs/src/main/java/deploymentevents/PlanSpec.java:[32,28] cannot find symbol
[ERROR] symbol: class plugins
[ERROR] location: package com.atlassian.bamboo
[ERROR] /bamboo-specs/src/main/java/deploymentevents/PlanSpec.java:[135,17] cannot find symbol
[ERROR] symbol: class AnyTrigger
[ERROR] location: class deploymentevents.PlanSpec
[ERROR] /bamboo-specs/src/main/java/deploymentevents/PlanSpec.java:[148,17] cannot find symbol
[ERROR] symbol: class AnyTrigger
[ERROR] location: class deploymentevents.PlanSpec
[ERROR] -> [Help 1]
[ERROR] 
```

<br />

<br />

I have tried adding:  

import com.atlassian.bamboo.plugins;  

however, no change in behavior.   

I also do not understand the \`Add com.atlassian.bamboo.plugins:afterdeployment-bamboo-specs:0.9 as dependency to your specs pom.xml to make use of this trigger builder.\` comment. I have a colleague who believes I do not need to touch the pom.xml.  

What am I missing to get this to compile? I used the View Plan As Java Specs option in bamboo for the above code.   
Thank you!


Answers:
author: Eduardo Alvarenga
body: Hello [@jzajac2](/t5/user/viewprofilepage/user-id/583373)

The After Deployment Trigger should be added to the Deployment Environment configuration and not to the Plan configuration.

The best way to find the required packages (and sample code) for that would be to create a Deployment Environment using the UI add the trigger there and later export it as Java Specs to understand what your requirements are.

Follow this path on your Environment configuration view:

* ... \>\> *View Project as Java Specs*

Best regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: jzajac2
body: To clarify, I already have a working Plan configured manually via the UI. I am trying to write the specs for that, and I cannot get it to compile. I am already using the "*View Project as Java Specs* "  

re: "The After Deployment Trigger should be added to the Deployment Environment configuration and not to the Plan configuration."  

Are you saying that the "Default Plan Configuration \| Triggers \| Select trigger \| After deployment" dialog in the UI, does not have a supported correlating Java Spec equivalent?  

If it does, can you show me a simple code project Plan with Java Specs, demonstrating an After Deployment Trigger working?  

<br />

<br />


author: Eduardo Alvarenga
body: As I have mentioned:
> The After Deployment Trigger should be added to the Deployment Environment configuration and not to the Plan configuration.

The way you are using it will not work in a Plan. You must add that configuration in your Deployment Environment.

Here's an example:

```
new Environment("OSALVA")
    .description("DEP")
    .tasks(new CleanWorkingDirectoryTask(),
        new ScriptTask()
            .inlineBody("echo hello world"),
    .triggers(new AfterSuccessfulDeploymentTrigger("Deployment")
            .name("After successful deployment")));
```

Cheers,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**