# KETTLE Variables

{% hint style="warning" %}

#### **Workshop - Kettle Variables**

Use variables to avoid hardcoded paths and values.

Use `kettle.properties` to store global variables for Spoon.

In this workshop, you will create a global variable. You will then use it in a transformation.

**What You'll Accomplish:**

* Access and edit the kettle.properties configuration file
* Define a global variable for jobs and transformations
* Use both variable formats (`${VAR}` and `%%VAR%%`)
* Insert variables with `Ctrl+Space`

**Prerequisites:** Pentaho Data Integration installed and configured

**Estimated Time:** 10 minutes
{% endhint %}

***

{% hint style="info" %}

#### **Global Variables - kettle.properties**

Variables can be used throughout Pentaho Data Integration, including in transformation steps and job entries. You define variables by setting them with the Set Variable step in a transformation or by setting them in the kettle.properties file in the directory.

Use variables by either retrieving them with the Get Variable step or by using metadata strings like:

* `${VARIABLE}`
* `%%VARIABLE%%`

You can mix both formats. The first is Unix-style. The second is Windows-style.

Fields that support variables show the blue `${}` icon.

Press `Ctrl+Space` to insert a variable in those fields. Hover over the icon to see help.
{% endhint %}

{% embed url="<https://www.loom.com/share/89d5419da317432eb272b583e30f8904?hideEmbedTopBar=true&hide_owner=true&hide_share=true&hide_title=true>" %}
KETTLE Variables
{% endembed %}

{% file src="<https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2FHGWMII2ZQhHMvMPjNRZm%2Fkettle.properties?alt=media&token=c3e51614-5b50-439b-8aa6-2fdf11446d78>" %}

***

1. Start Pentaho Data Integration.

{% hint style="info" %}
{% tabs %}
{% tab title="Windows (PowerShell)" %}

```powershell
Set-Location C:\Pentaho\design-tools\data-integration
.\spoon.bat
```

{% endtab %}

{% tab title="macOS / Linux" %}

```bash
cd ~/Pentaho/design-tools/data-integration
./spoon.sh
```

{% endtab %}
{% endtabs %}
{% endhint %}

2. Select Edit -> Edit the kettle.properties file
3. Highlight the first row and right mouse click, and select the following option.

<figure><img src="https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2Fgit-blob-42b90519ddbe4836bc15b6d8b77a223343b6183b%2Fset%20kettle%20variable.png?alt=media" alt=""><figcaption><p>Global variables</p></figcaption></figure>

4. Add a `DIR_SAMPLES` variable for your OS.

{% tabs %}
{% tab title="Windows" %}
Add this line:

```properties
DIR_SAMPLES=C:/Temp
```

{% endtab %}

{% tab title="Linux/macOS" %}
Add this line:

```properties
DIR_SAMPLES=/home/pentaho/Temp
```

{% endtab %}
{% endtabs %}

5. Save.

{% hint style="info" %}
Spoon loads `kettle.properties` on startup.

If variables do not show up, restart Spoon.
{% endhint %}

{% hint style="info" %}
You can also edit `kettle.properties` manually.

Default locations:

* Windows: `C:\Users\<username>\.kettle\kettle.properties`
* Linux/macOS: `~/.kettle/kettle.properties`

The PowerShell script uses [nano](https://github.com/okibcn/nano-for-windows) which was installed using [scoop](https://scoop.sh/)
{% endhint %}

6. Open a terminal.

{% tabs %}
{% tab title="Windows (PowerShell)" %}

```powershell
cd \
cd Workshop--Data-Integration\Scripts
.\edit-kettle.properties.ps1
```

{% endtab %}

{% tab title="Linux/macOS" %}

```bash
cd
cd ~/.kettle
nano kettle.properties
```

{% endtab %}
{% endtabs %}

<figure><img src="https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2Fgit-blob-644114f3a0ca33ba30f6cfd590d73a6ab51cf87a%2Fkettle.png?alt=media" alt="" width="563"><figcaption><p>kettle.properties - Linux</p></figcaption></figure>

{% hint style="info" %}
Verify in Spoon:

1. Open any step property that shows the blue `${}` icon.
2. Press `Ctrl+Space`.
3. Search for `DIR_SAMPLES`.
4. Insert it into the field.
   {% endhint %}

<div align="center"><figure><img src="https://3680356391-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZpCSy6Skj215f4oWypdc%2Fuploads%2Fgit-blob-1adc64a1b6089dd5b116af6015ec17292ab829d9%2Fvariable%20in%20trans.png?alt=media" alt="" width="375"><figcaption><p>Global variable in Transformation</p></figcaption></figure></div>

{% embed url="<https://docs.pentaho.com/pdia-data-integration/data-integration-perspective-in-the-pdi-client/advanced-topics-pdi-perspective/pdi-run-modifiers/variables/kettle-variables>" %}

***
