Export variables from Octopus project to json file

主宰稳场 提交于 2021-02-19 08:24:05

问题


Is there any way to export Octopus variables to json file, using "Command" step in Jenkins? According to official Octopus documentation I only able to export Projects and Releases.

Is there any way to export particular variables from particular project?


回答1:


Currently you can not do this using Octo.exe.

However you can still use Octopus REST API for your purpose.

First you have to create a API Key, which is required to access those APIs. Then call following API end point to get your specific project.

https://<your-octopus-installation>/api/projects/<project name>

Then response JSON contains VariableSetId which you should use for following request.

https://<your-octopus-installation>/api/variables/<VariableSetId>

For each of the above requests you should provide X-Octopus-ApiKey HTTP header with the API key as the value. Please refer this for more details.

Please note that you won't get the values of sensitive variables.

Tips: When you access the Octopus via browser, observe the HTTP requests it perform. That will helps you to understand, API calls that needs to be performed, to achieve your requirement.

If you are in to C# you can try Octopus.Client




回答2:


You can also export your Octopus Deploy configuration to JSON files using a PowerShell* module I just released:

https://github.com/DTW-DanWard/OctopusDeployUtilities

You can use Octopus Deploy Utilities (ODU) to export some or all of your data by REST API type. It also post processes your export data, performing ID -> name look ups for you. It also comes with a bunch of helpful utilities, like a function that gathers all data in an export into a single object so you can programmatically parse, report and even unit test your configuration.

Note: you might have difficulty exporting just the variable sets by themselves from your Octopus Deploy server. Internally Octopus Deploy stores every revision of every variable set and when you call the API to pull all the variableset data, your API call is likely to time out because of all those revisions. ODU works around that by only fetching the latest variable set data actively being used by projects and included library variable sets.

*It's written and tested in PowerShell Core so it'll run on all OSes. It also runs well in Windows PowerShell 5.



来源:https://stackoverflow.com/questions/49449510/export-variables-from-octopus-project-to-json-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!