{"id":31018,"date":"2022-08-17T23:04:49","date_gmt":"2022-08-17T23:04:49","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=31018"},"modified":"2022-12-23T05:47:45","modified_gmt":"2022-12-23T05:47:45","slug":"xl-release-tutorial-variables","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/xl-release-tutorial-variables\/","title":{"rendered":"XL Release Tutorial: Variables"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Using a List variable as a value in the List box variable types<\/h2>\n\n\n\n<p>You can create a List variable and use it as a possible value for a List box variable.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a&nbsp;<a href=\"https:\/\/docs.digital.ai\/bundle\/devops-release-version-v.22.2\/page\/release\/how-to\/configure-global-variables.html\" target=\"_blank\" rel=\"noopener\">global variable<\/a>&nbsp;or a&nbsp;<a href=\"https:\/\/docs.digital.ai\/bundle\/devops-release-version-v.22.2\/page\/release\/how-to\/create-release-variables.html#create-a-release-variable-on-the-variables-screen\" target=\"_blank\" rel=\"noopener\">release variable<\/a>&nbsp;with the type&nbsp;<strong>List<\/strong>.<\/li><li>When you create a new variable and select the type&nbsp;<strong>List box<\/strong>, click the button next to the&nbsp;<strong>Possible values<\/strong>&nbsp;to switch between a list of normal values or a variable of type&nbsp;<strong>List<\/strong>.<img decoding=\"async\" alt=\"List box variable\" src=\"https:\/\/digitalai-be-prod.zoominsoftware.io\/bundle\/devops-release-version-v.22.2\/page\/release\/images\/variable-list-box.png?_LANG=enus\"><\/li><li>Select the second option and choose a&nbsp;<strong>List<\/strong>&nbsp;type variable.<\/li><li>Click&nbsp;<strong>Save<\/strong>.<\/li><\/ol>\n\n\n\n<p>You can use the&nbsp;<strong>List box<\/strong>&nbsp;variable in templates, releases, or tasks allowing users to select the values from predefined&nbsp;<strong>List<\/strong>&nbsp;variable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using lists of Applications or Environments in the List box variable types<\/h2>\n\n\n\n<p>You can choose a list of Applications or Environments to be used as possible values for a&nbsp;<strong>List box<\/strong>&nbsp;variable.<\/p>\n\n\n\n<p>Please specify the run-as user and password on the template properties as those credentials will be used to retrieve the available Applications and Environments.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note<\/strong>: Applications or environments will only be retrieved when the new release is being created and during the User Input task. In all other cases &#8211; such as manually changing variable values in either a Template or Release &#8211; the list of values will be empty.<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dynamically-populating-a-list-box-variable-type-using-a-custom-script\">Dynamically populating a List box variable type using a custom script<\/h3>\n\n\n\n<p>You can use a script to dynamically retrieve possible values inside a List box variable.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a new List box variable.<\/li><li>Select&nbsp;<strong>Value provider<\/strong>&nbsp;as the Value provider type.<img decoding=\"async\" alt=\"List box variable_with_value_provider\" src=\"https:\/\/digitalai-be-prod.zoominsoftware.io\/bundle\/devops-release-version-v.22.2\/page\/release\/images\/value-provider-list-box.png?_LANG=enus\"><\/li><li>Select the&nbsp;<strong>Script value provider<\/strong>.<\/li><li>Depending on the selected script, you will have different input fields. The script will be evaluated when creating a release.<\/li><li>Click&nbsp;<strong>Save<\/strong>.<\/li><\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note<\/strong>: Applications or environments will only be retrieved when the new release is being created and during the User Input task. In all other cases &#8211; such as manually changing variable values in either a Template or Release &#8211; the list of values will be empty.<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a custom script value provider<\/h2>\n\n\n\n<p>Creating a new script value provider is similar to the&nbsp;<a href=\"https:\/\/docs.digital.ai\/bundle\/devops-release-version-v.22.2\/page\/release\/concept\/api-and-scripting-overview.html#plugin-tasks\" target=\"_blank\" rel=\"noopener\">Plugin tasks<\/a>. For a more detailed explanation of how to extend the Release type system, see&nbsp;<a href=\"https:\/\/docs.digital.ai\/bundle\/devops-release-version-v.22.2\/page\/release\/how-to\/create-custom-task-types.html\" target=\"_blank\" rel=\"noopener\">Defining a custom task<\/a>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"example-script-value-provider\">Example script value provider<\/h5>\n\n\n\n<p>In the&nbsp;<code>synthetic.xml<\/code>&nbsp;file, you must extend&nbsp;<code>xlrelease.JythonProvider<\/code>&nbsp;or&nbsp;<code>xlrelease.GroovyProvider<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">synthetic<\/span> <span class=\"hljs-attr\">xmlns:xsi<\/span>=<span class=\"hljs-string\">\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span>\n       <span class=\"hljs-attr\">xmlns<\/span>=<span class=\"hljs-string\">\"http:\/\/www.xebialabs.com\/deployit\/synthetic\"<\/span>\n       <span class=\"hljs-attr\">xsi:schemaLocation<\/span>=<span class=\"hljs-string\">\"http:\/\/www.xebialabs.com\/deployit\/synthetic synthetic.xsd\"<\/span>&gt;<\/span>\n\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">type<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"test.Test2ValueProvider\"<\/span> <span class=\"hljs-attr\">extends<\/span>=<span class=\"hljs-string\">\"xlrelease.JythonProvider\"<\/span> <span class=\"hljs-attr\">label<\/span>=<span class=\"hljs-string\">\"Sample value provider with CI ref\"<\/span>\n            <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"This value provider has CI ref parameter that points to JIRA server.\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"jiraServer\"<\/span> <span class=\"hljs-attr\">label<\/span>=<span class=\"hljs-string\">\"JIRA server\"<\/span> <span class=\"hljs-attr\">referenced-type<\/span>=<span class=\"hljs-string\">\"jira.Server\"<\/span> <span class=\"hljs-attr\">kind<\/span>=<span class=\"hljs-string\">\"ci\"<\/span> <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"JIRA server to use\"<\/span> \/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"username\"<\/span>  <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\">\"false\"<\/span> <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"Overrides the username used to connect to the server\"<\/span>\/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"password\"<\/span> <span class=\"hljs-attr\">password<\/span>=<span class=\"hljs-string\">\"true\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\">\"false\"<\/span> <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"Overrides the password used to connect to the server\"<\/span>\/&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">type<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">synthetic<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can store value provider scripts in the&nbsp;<code>ext<\/code>&nbsp;or&nbsp;<code>plugins<\/code>&nbsp;directory of the Release server.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use&nbsp;<code>ext<\/code>&nbsp;when you are developing a custom value provider. The&nbsp;<code>ext<\/code>&nbsp;directory contains custom type definitions in the&nbsp;<code>synthetic.xml<\/code>&nbsp;file. Scripts are placed in the subdirectories of&nbsp;<code>ext<\/code>.<\/li><li>The&nbsp;<code>plugins<\/code>&nbsp;directory contains bundled plugins that are packaged in a single zip file with the&nbsp;<code>.jar<\/code>&nbsp;extension.<\/li><\/ul>\n\n\n\n<p>For the value provider defined above, Release will try to find and execute the python script at this location:&nbsp;<code>test\/Test2ValueProvider.py<\/code>. Value provider scripts must return a list of objects in the variable named&nbsp;<code>result<\/code>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong>&nbsp;The properties of the value provider will be injected into the script as well&nbsp;<strong>as a dictionary<\/strong>. As a result, you do not need to access the properties as&nbsp;<code>valueProvider.jiraServer<\/code>&nbsp;but use&nbsp;<code>jiraServer<\/code>, instead.<\/p><\/blockquote>\n\n\n\n<p>The following script can be used to display the title of the JIRA server passed as a parameter to the value provider defined above:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># let's connect to the provided jiraServer<\/span>\nfrom xlrelease.HttpRequest import HttpRequest\n<span class=\"hljs-comment\"># example of request to the Jira server<\/span>\nreq = HttpRequest(jiraServer)\n<span class=\"hljs-comment\"># ...<\/span>\nresult = &#91;jiraServer&#91;<span class=\"hljs-string\">\"title\"<\/span>]]\n<span class=\"hljs-comment\"># or<\/span>\n<span class=\"hljs-comment\"># result = &#91;valueProvider.jiraServer.title]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can add the following properties to the&nbsp;<code>&lt;type&gt;<\/code>&nbsp;element to further customize your value provider:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>scriptLocation<\/code>: Specifies a custom script location that overrides the default rules.<\/li><\/ul>\n\n\n\n<p>This is an example of a value provider that generates a range of numbers:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">synthetic<\/span> <span class=\"hljs-attr\">xmlns:xsi<\/span>=<span class=\"hljs-string\">\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span>\n       <span class=\"hljs-attr\">xmlns<\/span>=<span class=\"hljs-string\">\"http:\/\/www.xebialabs.com\/deployit\/synthetic\"<\/span>\n       <span class=\"hljs-attr\">xsi:schemaLocation<\/span>=<span class=\"hljs-string\">\"http:\/\/www.xebialabs.com\/deployit\/synthetic synthetic.xsd\"<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">type<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"test.TestValueProvider\"<\/span> <span class=\"hljs-attr\">extends<\/span>=<span class=\"hljs-string\">\"xlrelease.JythonProvider\"<\/span> <span class=\"hljs-attr\">label<\/span>=<span class=\"hljs-string\">\"Sample script value provider\"<\/span>\n          <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"This value provider has two parameters for range.\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"param1\"<\/span> <span class=\"hljs-attr\">label<\/span>=<span class=\"hljs-string\">\"Lower bound\"<\/span> <span class=\"hljs-attr\">default<\/span>=<span class=\"hljs-string\">\"1\"<\/span> <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"Minimum value.\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\">\"false\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"param2\"<\/span> <span class=\"hljs-attr\">label<\/span>=<span class=\"hljs-string\">\"Upper bound\"<\/span> <span class=\"hljs-attr\">default<\/span>=<span class=\"hljs-string\">\"5\"<\/span> <span class=\"hljs-attr\">description<\/span>=<span class=\"hljs-string\">\"Maximum value.\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\">\"false\"<\/span> \/&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">type<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">synthetic<\/span>&gt;<\/span>\n\nPlace the corresponding script into test\/TestValueProvider.py:\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">def generateRange():\n    t = range(long(valueProvider.param1), long(valueProvider.param2))\n    <span class=\"hljs-keyword\">return<\/span> t\n\nresult = generateRange()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Refernce<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/docs.digital.ai\/bundle\/devops-release-version-v.22.2\/page\/release\/how-to\/configure-global-variables.html<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Using a List variable as a value in the List box variable types You can create a List variable and use it as a possible value for a List box variable. Create a&nbsp;global variable&nbsp;or a&nbsp;release variable&nbsp;with the type&nbsp;List. When you create a new variable and select the type&nbsp;List box, click the button next to the&nbsp;Possible&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-31018","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=31018"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31018\/revisions"}],"predecessor-version":[{"id":31020,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/31018\/revisions\/31020"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=31018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=31018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=31018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}