Copy release variables from one template to other

Hi Team,

Is there a way to copy release variables from one template to another apart from “DevOps as code”?

Use case: Hundreds of release variables needs to be copied from one template to other, just the release variables.

Thanks!

Ha, interesting! Can you tell me how you got to have 100s of release variable in a single template?

Is this a one-off or repeatable job? If it is a one-off I would go with DevOps as code.

Alternatively you can could a script task that uses the public API to copy variables from one template to another.

Kind regards,

Hes Siemelink

Hi Hes,

Thanks for the reply.

There are 100s of applications which have “key:value mapping” as variable(say 1 app has 10 key:value mapping as form of release variable). We create release for an application as per requirement.

We can use DevOps as code but there isn’t any option/flag to export only release variables in yaml. So, it’s bit tricky to modify other things like tasks and all in the yaml and yaml formatting mess up. Please let me know if I am missing something here.

It’s a repeatable job.

Can you point me out to the specific API to copy variables , I couldn’t find any in REST docs?

Thanks

I would export the yaml and just copy/paste the variable section.

In any case, how do you put those variables in the tasks?

https://docs.xebialabs.com/xl-release/10.0.x/rest-docs/#working-with-variables

First List all release/template variables, then loop over them and Create new release/template variable

1 Like

Most of the variables are used in ServiceNow: Create Change Request Task, Create Change Task, Update change/change Request Tasks.

easiest way is via a meta release template/release and a jython task inside:

Fetch variables from another release

rvar = releaseApi.getVariables(releaseidvar)
for r in rvar: 
    print "key:%s , value:%s \n" % (r._delegate.key,r._delegate.value)

or

myRelease = getCurrentRelease()
for r in myRelease.variables: 
   print "key:%s , value:%s \n" % (r.key, r.value)

More Examples here: https://github.com/xebialabs-community/xlr-jython-code-snippets

1 Like