Groovy: How to define a manipulated string as a variable?
<p>I'm writing a Jenkins pipeline as a code for an Android application.</p>

<p>I have the following strings:</p>

<pre><code>BUILDFLAV = "Staging"
BUILDTYPE = "Debug"
</code></pre>

<p>I want to define another variable called artifact_name which will look like:</p>

<pre><code>product_name-BUILDFLAV(in lowercase)-BUILDTYPE(in lowercase).apk
</code></pre>

<p>for example:</p>

<pre><code>App01-staging-debug.apk
</code></pre>

<p>Since I'm new to groovy i'm not sure that I'm doing it correctly.</p>

<p>I've defined 2 variables:</p>

<pre><code>aa = BUILDFLAV[0].toLowerCase()+BUILDFLAV.substring(1)
bb = BUILDTYPE[0].toLowerCase()+BUILDTYPE.substring(1)
</code></pre>

<p>This allows me to change the first char of each string from uppercase to lowercase.</p>

<p>Then, I want the artifact_name variable to look like so:</p>

<pre><code>App01-$(aa}-${bb}.apk
</code></pre>

<p>So I've tried something like that:</p>

<pre><code>artifact_name = "App01-${BUILDFLAV[0]}.toLowerCase()+${BUILDFLAV}.substring(1)+${BUILDTYPE[0]}.toLowerCase()+${BUILDTYPE}.substring(1).apk"
</code></pre>

<p>But it throws me an error.</p>

<p>Doing this, however, worked but seems like there's a more elegant way to do that:</p>

<pre><code>BUILDFLAV = "Staging"
BUILDTYPE = "Debug"
aa = BUILDFLAV[0].toLowerCase()+BUILDFLAV.substring(1)
bb = BUILDTYPE[0].toLowerCase()+BUILDTYPE.substring(1)
ARTIFACT_NAME = "App01-${aa}-${bb}.apk"
</code></pre>

<p>If you ask yourself why I'm not setting the variables in lowercase from the beginning is because the gradle task which is run in the build is using the first letter uppercase convention and what I'm trying to achieve is related to a more advanced step of the build.</p>

<p>Is it possible to achieve the same result by doing what I did in vars "aa" and "bb" in just one line? like the above example with artifact_name...</p>