Passing a Variable from Parent Project to Child Project


(jsidoti) #1

I’m using a Deploy a Release step in my ‘parent’ project to pass a variable along to a ‘child’ project. In the ‘Deploy a release - variables’ section I’ve defined a variable named myVar with a value of 5000.

In the ‘child’ project I’ve defined a Project variable named myVar and it has a value of #{myVar} (it was deemed easier to name the variables the same and allow the name collision with the ‘parent’ taking precedence.)

This is working but myVar doesn’t show up anywhere in a variable preview. I’m assuming it’s because it is a variable that doesn’t exist until the step is executed? Is there any way to get a preview of the passed variable?

Thanks.
Jamie


(Nick Josevski) #2

Hi Jamie,

Thanks for getting in touch. Project variables do not get shared between projects even when using Deploy a Release step. The Deploy a Release step is just to help co-ordinate multiple projects.

You mention collision and precedence, in talking about the variables - but they only work in isolation. If you happened to name a variable the same at the parent and child, they will always work independently in their respective projects.

With this is mind it’s why Preview Variables at the parent level will not factor in any child project variables and vice-versa.

There may be another way to achieve your objectives, let us know what your goal is we may be able to point you to a more suitable Octopus feature. If you haven’t considered Library Variable Sets that could be a starting point.

Regards,
Nick


(jsidoti) #3

I’m referring to the following in the Octopus documentation:

When I define a variable in the parent project ‘Deploy a release’ step as shown, it says they are “made available to steps within the child deployment’s process”.

It also mentions “Variables passed in will override existing variables in the child project if the names collide.”

Once the variable is defined in the parent project I have noticed that they do not appear in a variable preview (for either the parent or child project.)

  1. I was just wondering if there is any way to preview those variable values?

  2. Once the variable is defined in the parent ‘Deploy a release’ step (e.g. myVariable = somevalue), does a matching variable have to be defined in the child project or can the variable from the parent just be accessed as #{myVariable} within a child process step?

Thanks,
Jamie


(Nick Josevski) #4

Hi Jamie,

Sorry about the misunderstanding, we had forgotten about that way to set up variables, we were thinking about Project Variables, these variables are defined as part of the Deployment Process.

To answer your questions:

  1. Unfortunately no, they’re not currently supported by the existing project variable preview feature, so the only way to preview them is to look at the deployment process of the parent.

  2. They do not need to be defined in the child they can be simply referenced using the variable syntax. The thing to note is depending how they are used if you do try to deploy the child project in isolation and nothing supplies those variables that would have come from the parent it may fail. But if you always will be deploying from the parent or the usage of the variables can cope with them missing it will be fine.

For some extra information; the variables defined in the parent as part of the “Deploy Release Step”, form part of the that deployment process snapshot that’s linked to the release. They are not part of the variable snapshot for the parent or child projects, they come together at deployment time.

Hope that helps, let us know if you have further questions.

Regards,
Nick


(jsidoti) #5

Yes, that’s quite helpful. Thank you very much!

Take care,

Jamie