Skip to content

Commit 8475cde

Browse files
authored
Fix docs: Correction to Substitute Variables in Templates (#3207)
* Correct which variable is used and what the default behavior is * update mod date * fixing lint errors
1 parent 19f0d18 commit 8475cde

1 file changed

Lines changed: 40 additions & 37 deletions

File tree

src/pages/docs/projects/steps/configuration-features/substitute-variables-in-templates.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: src/layouts/Default.astro
33
pubDate: 2023-01-01
4-
modDate: 2023-01-01
4+
modDate: 2026-06-12
55
title: Substitute variables in templates
66
description: Package steps have a feature that allows you to replace variables in any file.
77
navOrder: 80
@@ -17,65 +17,68 @@ You can perform very complex transformations in any kind of file using this feat
1717
The following example shows you how to use the Substitute Variables in Templates feature to provide a different login form to the different environments you're deploying to. In this example, we're deploying to a **Test** and **Production** environment.
1818

1919
1. Create the login variable in Octopus. From the: [project](/docs/projects) overview page, click **Variables**.
20-
- Enter a the name for the variable, for instance, *LoginURL*.
21-
- Enter the first value for the variable, for instance, *https://test.example.com/login*.
22-
- Scope this value to the test environment by clicking the *Define Scope* field and selecting the test environment.
23-
- Click **ADD ANOTHER VALUE**.
24-
- Enter the second value for the variable, for instance, *https://example.com/login*.
25-
- Scope this value to the production environment by clicking the *Define Scope* field and selecting the production environment, and click **SAVE**. In this example, you now have the following variables:
26-
27-
| Variable Name | Value | Scope |
28-
| ----------------------- | --------------- | -------- |
29-
| LoginURL | `https://test.example.com/login` | Test |
30-
| LoginURL | `https://example.com/login` | Production |
20+
21+
- Enter a the name for the variable, for instance, *LoginURL*.
22+
- Enter the first value for the variable, for instance, *<https://test.example.com/login>*.
23+
- Scope this value to the test environment by clicking the *Define Scope* field and selecting the test environment.
24+
- Click **ADD ANOTHER VALUE**.
25+
- Enter the second value for the variable, for instance, *<https://example.com/login>*.
26+
- Scope this value to the production environment by clicking the *Define Scope* field and selecting the production environment, and click **SAVE**. In this example, you now have the following variables:
27+
28+
| Variable Name | Value | Scope |
29+
| ------------- | -------------------------------- | ---------- |
30+
| LoginURL | `https://test.example.com/login` | Test |
31+
| LoginURL | `https://example.com/login` | Production |
3132

3233
2. Include the loginURL variable in the app you're deploying, by adding the variable `#{LoginURL}`. For instance:
3334

34-
```xml
35-
<authentication mode="Forms">
36-
<forms loginUrl="#{LoginURL}" timeout="2880" />
37-
</authentication>
38-
```
35+
```xml
36+
<authentication mode="Forms">
37+
<forms loginUrl="#{LoginURL}" timeout="2880" />
38+
</authentication>
39+
```
3940

4041
3. Define the deployment process, by clicking **Process** from the project overview page, then select, **ADD STEP**.
4142
4. Select the **Deploy a Package** step.
4243
5. From the [Step](/docs/projects/steps) Template page, click the **Configure Features** link.
4344
6. Check the **Substitute Variables in Templates** check-box and click **Ok**.
4445

45-
:::figure
46-
![Substitute Variables in Templates feature](/docs/img/projects/steps/configuration-features/images/substitute-variables.png)
47-
:::
46+
:::figure
47+
![Substitute Variables in Templates feature](/docs/img/projects/steps/configuration-features/images/substitute-variables.png)
48+
:::
4849

49-
When you return to your deployment process, you will see the **Substitute Variables in Templates** option has been added to the **Features** section of the deployment process.
50+
When you return to your deployment process, you will see the **Substitute Variables in Templates** option has been added to the **Features** section of the deployment process.
5051

5152
7. Add the [step](/docs/projects/steps) details:
52-
- Enter a name for the step.
53-
- Select the targets where the step should run.
54-
- Select the [package feed](/docs/packaging-applications/package-repositories/) where the [package](/docs/packaging-applications) will be available.
55-
- Enter the [package ID](/docs/packaging-applications/#package-id) for the package to be deployed.
53+
54+
- Enter a name for the step.
55+
- Select the targets where the step should run.
56+
- Select the [package feed](/docs/packaging-applications/package-repositories/) where the [package](/docs/packaging-applications) will be available.
57+
- Enter the [package ID](/docs/packaging-applications/#package-id) for the package to be deployed.
58+
5659
8. In the **Target Files** text area, enter the files, as a newline separated list, that you want to perform the variable substitution on. You need to state the full path of the file, relative to the installation directory. In our example, that includes any file that references the `{LoginURL}` variable. For instance:
5760

58-
```
59-
config\app.config
60-
```
61+
```text
62+
config\app.config
63+
```
6164

6265
9. If you want to specify the encoding for the transformed file, enter the encoding in the **Output file encoding** field.
6366

64-
The default option for Output file encoding (Detect from template) will use the Byte Order Mark (BOM) of the file to determine the encoding.
67+
The default option for Output file encoding (Detect from template) will use the Byte Order Mark (BOM) of the file to determine the encoding.
6568

6669
10. Add any [conditions](/docs/projects/steps/conditions) you need to specify for the step, and then click **SAVE**.
6770

68-
When the application is deployed to your **test** and **production** environments, each environment will include the login URL you defined for the specific environment.
71+
When the application is deployed to your **test** and **production** environments, each environment will include the login URL you defined for the specific environment.
6972

70-
From here you can use the project overview menu to continue defining your process, or click **CREATE RELEASE** to create a [release](/docs/releases) and deploy your application.
73+
From here you can use the project overview menu to continue defining your process, or click **CREATE RELEASE** to create a [release](/docs/releases) and deploy your application.
7174

72-
:::div{.warning}
73-
If you include a configuration file that you are also doing a [transformation](/docs/projects/steps/configuration-features/configuration-transforms/) and [variable](/docs/projects/steps/configuration-features/xml-configuration-variables-feature/) swap on, the variable change will run under the 'substitute variables in templates' before the transformation as defined in the [package deployment feature ordering](/docs/deployments/packages/package-deployment-feature-ordering) process.
74-
:::
75+
:::div{.warning}
76+
If you include a configuration file that you are also doing a [transformation](/docs/projects/steps/configuration-features/configuration-transforms/) and [variable](/docs/projects/steps/configuration-features/xml-configuration-variables-feature/) swap on, the variable change will run under the 'substitute variables in templates' before the transformation as defined in the [package deployment feature ordering](/docs/deployments/packages/package-deployment-feature-ordering) process.
77+
:::
7578

76-
:::div{.warning}
77-
By default, **warnings** will be treated as **errors** when replacing variables in files using this feature. To override this behavior, set the variable **Octopus.Action.Package.IgnoreVariableReplacementErrors** to **True** in your project. By doing this, warnings will be treated as such and the deployment will not be marked as failed.
78-
:::
79+
:::div{.warning}
80+
By default, when variable substitution fails, the deployment will **not** fail. This variable substitution error will be logged at the **Verbose** level. To fail the step when substitution fails, set the variable **OctopusShouldFailDeploymentOnSubstitutionFails** to **True** in your project.
81+
:::
7982

8083
## Examples {#SubstituteVariablesInFiles-SomeExamples}
8184

0 commit comments

Comments
 (0)