after deployment trigger result variables
Asked by Prem Chudzinski _extensi_:

Hi,  

I need to pass a variable deployment.environmentName back to my plan but that doesn't happen.

<br />

**This is my workflow:**build -\> deployment to multiple environments -\> after deployment trigger BuildPlan to run integration tests

On the screenshot attached to the marketplace listing I can see some deploymentResult Keys and variables?

**<https://marketplace.atlassian.com/plugins/com.atlassianlab.bamboo.plugins.bamboo-after-deployment-trigger-plugin/server/overview>**

<br />

How do I pass them to a triggered plan?

Cheers

Przemyslaw


Answers:
author: rsperafico
body: Hello [@Prem Chudzinski _extensi_](/t5/user/viewprofilepage/user-id/551438),

You can retrieve the *deployment.environmentName* variable by calling it in a Script task as example:

```
echo "bamboo.deployment.environmentName" ${bamboo.deployment.environmentName}
```

So in your example:
> build -\> deployment to multiple environments -\> after deployment trigger BuildPlan to run integration tests

"build", lets say PROJ-PLAN  
"deployment to multiple environments", lets say QA  
"after deployment trigger BuildPlan", lets say PROJ-TESTS

In PROJ-TESTS-JOB1, you could add a Script task with the above mentioned, resulting on:

```
build 02-Jan-2018 19:21:45 bamboo.deployment.environmentName QA
```

Kind regards,

Rafael

comments: author: Prem Chudzinski _extensi_
body: That seems to be the solution,

but now I've got a new issue with the after-deployment-trigger

Here's the scenario

1. PROJ-PLAN1

2. Deployment to QA1 and QA2

3. PROJ-PLAN2 (integration tests) using After Deployment Trigger

At this point I assume the QA1 and QA2 deployments should trigger Proj-PLAN2 twice. I use here

```
bamboo.deployment.environmentName
```

To determine against which environment my integration tests should be executed.

What is happening?

Proj-PLAN2 is triggered once.

Sometimes by QA1 sometimes by QA2

In the trigger configuration I've selected Triggering Deployment to "Any" but also tried to create two triggers for QA1 and QA2.

Same result.

Seems like a bug to me.

What do you think?


author: Prem Chudzinski _extensi_
body: In the logs I can see

2018-01-03 10:15:42,761 INFO \[10-BAM::PlanExec:pool-17-thread-3\] \[ChainExecutionManagerImpl\] Build Proj-PLAN2-JOB1-66 has been dispatched

Only once, and should be triggered twice.


author: rsperafico
body: Hello [@Prem Chudzinski _extensi_](/t5/user/viewprofilepage/user-id/551438),

Could you please go to **Bamboo administration \>\> Overview \>\> Plans \>\> Concurrent builds** and **Enable** it, setting the **Default number of concurrent builds allowed** to **2**

Save the configuration and re-do the testing.
> Bamboo's concurrent builds feature allows you to build a plan concurrently on several agents. You might find this useful if a plan is likely to be [triggered](https://confluence.atlassian.com/display/BAMBOO/Triggering+builds) again before the current build completes.

For more information - [Configuring concurrent builds](https://confluence.atlassian.com/pages/viewpage.action?pageId=289277193 "Configuring concurrent builds")

Kind regards,

Rafael


author: Prem Chudzinski _extensi_
body: Hi [@rsperafico](/t5/user/viewprofilepage/user-id/781554),

Yes that helped but that seems to be very strange behaviour.

I'm looking into the plugin code and API

```
nonBlockingPlanExecutionService.tryToStart(plan, triggeringAction);
```

<https://docs.atlassian.com/atlassian-bamboo/6.2.3/com/atlassian/bamboo/plan/NonBlockingPlanExecutionService.html#tryToStart-com.atlassian.bamboo.trigger.Triggerable-com.atlassian.bamboo.build.BuildDetectionAction->

> In other words, the method should be used for cases where build absolutely, positively needs to trigger (unless encountering internal error or **hitting concurrent build limit**)

I do understand now that it was hitting the concurrent build limit. But no errors or logs were printed out to the end user.

I'd expect all triggered builds to be queued.

Will this method put the execution into queue?

<https://docs.atlassian.com/atlassian-bamboo/6.2.3/com/atlassian/bamboo/plan/PlanExecutionManager.html#start-com.atlassian.bamboo.plan.cache.ImmutableChain-com.atlassian.bamboo.build.BuildDetectionAction-com.atlassian.bamboo.util.AcquisitionPolicy->


author: rsperafico
body: Hello [@Prem Chudzinski _extensi_](/t5/user/viewprofilepage/user-id/551438),

Thank you for raising the issue on <https://bitbucket.org/atlassianlabs/bamboo-after-deployment-trigger/issues/3/multiple-environments-not-triggering-a>

And regarding to your inquire, "start" would do the job.

Kind regards,

Rafael


author: Prem Chudzinski _extensi_
body: Just tried it start doesn't work.


author: rsperafico
body: Hello [@Prem Chudzinski _extensi_](/t5/user/viewprofilepage/user-id/551438),

You should be looking at *com.atlassian.bamboo.plan.NonBlockingPlanExecutionService::tryToStart* in the same way <https://bitbucket.org/atlassianlabs/bamboo-after-deployment-trigger/src/db69092655fd6a20500c3217b64e45301f495871/src/main/java/com/atlassianlab/bamboo/plugins/afterdeploymenttrigger/DeploymentResultListener.java> does.

Kind regards,

Rafael


author: Prem Chudzinski _extensi_
body: [@rsperafico](/t5/user/viewprofilepage/user-id/781554)

I've modified the plugin itself to use PlanExecutionManager instead of *NonBlockingPlanExecutionService.*

I just think my use case is not supported by bamboo.

I'd need an API that would enforce bamboo to queue next job regardless of the **concurrent build limit.**

My use case is pretty common.

Build-\>Multiple Deployments-\>Integration tests against each environment using a single Plan.

Additionally it should be possible to push some custom variables from the deployment result to the triggered Plan.

At the moment I' have to use the default

```
bamboo.deployment.environmentName
```

to determine which env has triggered my integration tests.

I need to pass more variables like host name for example.


author: Artur Grigoryan
body: hi. Were you able to pass more variables?


author: Bill Rebey
body: Note that the answer provided by [@rsperafico](/t5/user/viewprofilepage/user-id/781554) above:

```
echo "bamboo.deployment.environmentName" ${bamboo.deployment.environmentName}
```

Is for use in shell scripts that are run by the bamboo agent.

For use within a program, the actual environment variables have the dots are replaced with underscores, such as this (C# .Net example):

```

strTargetEnv = Environment.GetEnvironmentVariable("bamboo_deployment_environmentName");

```