How to add the content of one file to another file in Octopus

Hi,

We use Octopus for our deployments.One of our project has a resource .xml file that also gets deployed via octopus. Now the requirement is that we have some shared content in the resource.xml file and some environment specific content in two separate resource files resource_Prod.xml and resource_EU.xml. Now my question is when I deploy the resource file , is there a way in octopus that depending upon the environment the environment specific resource files content gets added to the resource.xml. So that at the end in the specific environment I should have one resource.xml that should contain the common as well as the environment specific content.

Thank you,
Sumegha

Hi Sumegha,

Thanks for getting in touch! To add content from one file to another would require some custom scripting. To use environment-specific values, you can take advantage of variables scoped to an environment and using the appropriate value for that environment. You could then use variable substitution with the syntax #{VariableName} in your file (where you want it to be replace). Octopus will find the matching project variable name, and substitute the variable’s value.

Our documentation outlines the Substitute variables in files feature.

And we have a guide on using variable substitution syntax.

I hope this helps get you started! Let me know if you have any further questions going forward.

Kind regards,

Kenny

Hello Kenneth ,

Thanks for your reply. I had just one more question. Can this be done to abc.xml file verses abc.config file. Is it mandatory that the file has to have .config extension?

Looking forward for your reply.

Thanks,

Sumegha Shaw

Please consider the environment before printing. [Description: Description: cid:image002.jpg@01CC4C7E.600EBA70] http://www.google.com/imgres?imgurl=http://www.webbywebdesign.com.au/newsletter/go_green.jpg&imgrefurl=http://www.webbywebdesign.com.au/newsletter/facebook.htm&usg=__5r8TnT1-8INnheMfpI0kVuGF694=&h=35&w=35&sz=2&hl=en&start=193&zoom=1&itbs=1&tbnid=zG-uEeJeg3QCVM:&tbnh=35&tbnw=35&prev=/images%3Fq%3Dplease%2Bconsider%2Bthe%2Benvironment%2Bbefore%2Bprinting%2Bthis%2Bemail%2Blogo%26start%3D180%26hl%3Den%26sa%3DN%26gbv%3D2%26ndsp%3D20%26tbs%3Disch:1

image001.png

Hi Sumegha,

Thanks for following up! The files you perform variable substitution on does not have to have the .config extension, and can be done on any file that’s part of your package by defining it in the target files section. :slight_smile:

I hope this helps! Don’t hesitate to reach out if you have any further questions.

Kind regards,

Kenny

Thank you Kenneth, that really helps. I appreciate.

Sumegha Shaw

Please consider the environment before printing. [Description: Description: cid:image002.jpg@01CC4C7E.600EBA70] http://www.google.com/imgres?imgurl=http://www.webbywebdesign.com.au/newsletter/go_green.jpg&imgrefurl=http://www.webbywebdesign.com.au/newsletter/facebook.htm&usg=__5r8TnT1-8INnheMfpI0kVuGF694=&h=35&w=35&sz=2&hl=en&start=193&zoom=1&itbs=1&tbnid=zG-uEeJeg3QCVM:&tbnh=35&tbnw=35&prev=/images%3Fq%3Dplease%2Bconsider%2Bthe%2Benvironment%2Bbefore%2Bprinting%2Bthis%2Bemail%2Blogo%26start%3D180%26hl%3Den%26sa%3DN%26gbv%3D2%26ndsp%3D20%26tbs%3Disch:1

image001.png

Hi Sumegha,

You’re very welcome! I’m glad it helps. Don’t hesitate to reach out if you have any further questions in the future. :slight_smile:

Best regards,

Kenny

Hello Kenneth,

Actually thinking about it again , what if this xml is not a part of any project. Do you still think the solution is gonna work?

Thanks,
Sumegha Shaw

Please consider the environment before printing. [Description: Description: cid:image002.jpg@01CC4C7E.600EBA70] http://www.google.com/imgres?imgurl=http://www.webbywebdesign.com.au/newsletter/go_green.jpg&imgrefurl=http://www.webbywebdesign.com.au/newsletter/facebook.htm&usg=__5r8TnT1-8INnheMfpI0kVuGF694=&h=35&w=35&sz=2&hl=en&start=193&zoom=1&itbs=1&tbnid=zG-uEeJeg3QCVM:&tbnh=35&tbnw=35&prev=/images%3Fq%3Dplease%2Bconsider%2Bthe%2Benvironment%2Bbefore%2Bprinting%2Bthis%2Bemail%2Blogo%26start%3D180%26hl%3Den%26sa%3DN%26gbv%3D2%26ndsp%3D20%26tbs%3Disch:1

image001.png

Hello Kenneth,

So the issue is that I have a resource. xml file which is not a part of any solution or a project. It’s a standalone file along with few other image files that are contained in a different folder. We currently use octopus to deploy this to the dev and prod servers, so that it can be used by other project to display its data. What I did was I manually added another resource.PRODS.xml file to the folder with the transform in it. Now when I deploy it to prod I see the content of resource .xml and not resource.PROD.xml (though I do have resource.#{Octopus.Enviromet.Name}.xml => resource.xml defined in octopus). Any idea or suggestions will greatly be appreciated.

Thanks,
Sumegha Shaw

Please consider the environment before printing. [Description: Description: cid:image002.jpg@01CC4C7E.600EBA70] http://www.google.com/imgres?imgurl=http://www.webbywebdesign.com.au/newsletter/go_green.jpg&imgrefurl=http://www.webbywebdesign.com.au/newsletter/facebook.htm&usg=__5r8TnT1-8INnheMfpI0kVuGF694=&h=35&w=35&sz=2&hl=en&start=193&zoom=1&itbs=1&tbnid=zG-uEeJeg3QCVM:&tbnh=35&tbnw=35&prev=/images%3Fq%3Dplease%2Bconsider%2Bthe%2Benvironment%2Bbefore%2Bprinting%2Bthis%2Bemail%2Blogo%26start%3D180%26hl%3Den%26sa%3DN%26gbv%3D2%26ndsp%3D20%26tbs%3Disch:1

image001.png

Hi Sumegha,

Thanks for getting back in touch! As long as the config file name where you’re using the #{Octopus.Environment.Name} system variable matches your environment name, I don’t see a reason why this shouldn’t work. You can define an absolute path to your transformation files, and we have some examples of doing this in our Advanced configuration transforms doc page.

Does this help with what you’re trying to do? Let me know if I’ve misunderstood your scenario in anyway. :slight_smile:

Best regards,

Kenny