5

I would like to use a bamboo plan variable in a deployment project.

I inject the version of the project into ${bamboo.inject.version} during the build plan, and I would like to use it in the deployment project. (The artifact I am deploying uses the version in its name).

I've tried referencing ${bamboo.planRepository.inject.version} and ${bamboo.inject.version} but neither of these work.

I am happy to hear suggestions of other ways of doing this too.

Edit: I did manage to achieve the results I wanted by adding the properties file as a build artifact, then exporting it into the deployment project. This seems rather roundabout but works. Any other ideas appreciated!

natke
  • 743
  • 1
  • 9
  • 21

3 Answers3

2

As suggested by ToAsT, set the scope of your injected variables to Result first, then add a variable inject.version into your plan, and make sure you also have ${bamboo.inject.version} for release versioning field of the deployment project.

Ramius
  • 121
  • 8
1

You could potentially add that version info into the release name itself, but if what you're doing works then stick with that. Check out what's offered in the free plugins.

ToAsT
  • 296
  • 1
  • 5
  • How do I do this? When I look at the variables available (via Add variable to version link), the variable I want is not in the list. Only the standard bamboo variables (plan name etc) are there. – natke Jun 05 '17 at 16:55
  • I may have jumped to certain conclusions a little quickly. :) Which version of Bamboo are you using? I'm assuming (based on the variable names) that you're applying the version to the variable via the Bamboo Inject Variables task - or am I mistaken? If not, and if you're setting the variables on the Variables tab of the build plan, then those should be available within the associated deployment plan for a build. – ToAsT Jun 08 '17 at 03:59
  • We're using `5.15.0.1 build 51513 - 09 Feb 17`. I am using bamboo inject variables but they do not appear in the variables tab of the deploy project. I assume they are dynamically applied. I'm not sure how else this would be done. (Besides which if I have to inject the variables, I already have access to the value I want, so I am not sure what this would be saving) – natke Jun 09 '17 at 18:16
  • You're using a newer version of Bamboo than we are, but the task appears to be working correctly in our instance - we can inject variables and have them appear in the deployment plan (I'll double check at my workplace this week to see if there's something special happening there). The only other things I can suggest would be to change the namespace in the task to a different value (maybe it's overridden), ensure the deployment project is linked to the correct build plan, and ensure the scope of the variables you inject is set to Result (and not Local). I can edit my answer if any of these work – ToAsT Jun 19 '17 at 04:57
1

Yes you can, for that you need to use a task called Inject Variables.

  1. In your Build Plan Task creates a key=value file (can be a script task):
echo "DEPLOYMENT_VERSION={your_version_here}" > /etc/.version
  1. In the next task, use the Inject Variables task to export this variable through your build plan and deployment projects (that is related):
# this is the yaml used in bamboo-specs
version: 2
# ...
  tasks:
    - inject-variables:
        file: /etc/.version
        scope: RESULT # share between stages and deployment releases
        namespace: anything_you_want

When you run your deployment task, you can call the variable with the following name:

echo ${bamboo.anything_you_want.DEPLOYMENT_VERSION}

Sources: