You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+243Lines changed: 243 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,134 @@ The directory structure of a step package project is shown below:
41
41
*`package-lock.json` - The [specific package versions](https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json) to be retrieved by npm.
42
42
*`tsconfig.json` - The [TypeScript compiler options file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
43
43
44
+
## Creating a new target
45
+
46
+
Creating a new target involves creating the following files under the `steps/<target-name>-target/src` directory. In the case of this sample step package, we'll create them under `steps/hello-world-target/src`:
47
+
48
+
*`metadata.json`
49
+
*`inputs.ts`
50
+
*`executor.js`
51
+
*`ui.ts`
52
+
*`validation.ts`
53
+
54
+
### `metadata.json`
55
+
56
+
The `metadata.json` provides details about the target. A sample is shown below:
57
+
58
+
```json
59
+
{
60
+
"schemaVersion": "1.0.0",
61
+
"version": "0.0.0",
62
+
"type": "deployment-target",
63
+
"id": "hello-world-target",
64
+
"name": "Hello world target",
65
+
"description": "An example target that does nothing useful",
66
+
"categories": [
67
+
"Linux"
68
+
],
69
+
"launcher": "node"
70
+
}
71
+
```
72
+
73
+
*`schemaVersion` is the version of the metadata file. `1.0.0` is the only version available.
74
+
*`version` is the version of the target. Versioning is covered in detail [here](https://github.com/OctopusDeploy/Architecture/blob/main/Steps/Concepts/Versioning.md).
75
+
*`type` defines the type of resource tobe created. It must be `deployment-target` for a target.
76
+
*`id` is the resource ID.
77
+
*`name` is the name of the target displayed by the Octopus web UI.
78
+
*`description` is the description of the target displayed by the Octopus UI.
79
+
*`categories` is an array containing one or more step categories display by the Octopus UI where the target will be listed.
80
+
*`launcher` defines how the step is executed. A value of `node` means the step is executed by Node.js.
81
+
82
+
### `inputs.ts`
83
+
84
+
The `inputs.ts` file exports an interface defining the input fields required by the target. This interface is consumed by both `executor.ts` to read the values when performing the target's health check, and `ui.ts` to build up the form exposed in the Octopus web UI.
85
+
86
+
An example is shown below exposing a single string field:
87
+
88
+
```typescript
89
+
exportdefaultinterfaceHelloWorldTargetInputs {
90
+
greetingPrefix:string;
91
+
}
92
+
```
93
+
94
+
### `executor.ts`
95
+
96
+
Targets perform a health check to validate their inputs and check the state of the system they represent. This health check is performed by the function exposed by the `executor.ts` file.
97
+
98
+
The example below prints some text to the log during a health check, and will always pass, meaning the target is always healthy:
The form to be exposed by the Octopus web UI is defined in the `ui.ts` file. The form is defined as an instance of the `DeploymentTargetUI` interface, which has two functions: `createInitialInputs` and `editInputsForm`.
114
+
115
+
The `createInitialInputs` function allows the initial default field values to be defined.
116
+
117
+
The `editInputsForm` function provides a DSL for building the user interface. The first parameter is the inputs defined in `inputs.ts`. The second parameter is an instance of `AvailableStepComponents`, which has factory functions for creating various input widgets like text fields, lists, radio buttons etc.
118
+
119
+
Here we define the initial value of the `greetingPrefix` input to be `Hello`, and build the form with a single `text` input:
Form validation is defined in the `validate.ts` file. This file exports a function the returns an array of `ValueValidator` objects, and takes two parameters:
151
+
1. The step inputs as [input paths](https://github.com/OctopusDeploy/Architecture/blob/main/Steps/Concepts/InputsAndOutputs.md#input-paths).
152
+
2. A validation function that returns a `ValueValidator` and takes two parameters:
153
+
1. An input path.
154
+
2. A function the returns a string containing the error code (or returns nothing if there is no validation error) and provides the input value as the first parameter.
if (greeting==="") return"Greeting can not be empty";
166
+
}),
167
+
];
168
+
};
169
+
exportdefaultvalidateInputs;
170
+
```
171
+
44
172
## Creating a new step
45
173
46
174
Creating a new step involves creating the following files under the `steps/<step-name>/src` directory. In the case of this sample step package, we'll create them under `steps/hello-world/src`:
@@ -53,3 +181,118 @@ Creating a new step involves creating the following files under the `steps/<step
53
181
54
182
### `metadata.json`
55
183
184
+
The `metadata.json` provides details about the step. A sample is shown below:
185
+
186
+
```json
187
+
{
188
+
"schemaVersion": "1.0.0",
189
+
"version": "0.0.0",
190
+
"type": "step",
191
+
"id": "hello-world-upload",
192
+
"name": "Hello World",
193
+
"description": "An example step",
194
+
"categories": [
195
+
"BuiltInStep"
196
+
],
197
+
"canRunOnDeploymentTarget": false,
198
+
"launcher": "node"
199
+
}
200
+
```
201
+
202
+
The following fields make up this file:
203
+
204
+
*`schemaVersion` is the version of the metadata file. `1.0.0` is the only version available.
205
+
*`version` is the version of the step. Versioning is covered in detail [here](https://github.com/OctopusDeploy/Architecture/blob/main/Steps/Concepts/Versioning.md).
206
+
*`type` defines the type of resource tobe created. Valid values are `step` and `deployment-target`.
207
+
*`id` is the resource ID.
208
+
*`name` is the name of the step displayed by the Octopus web UI.
209
+
*`description` is the description of the step displayed by the Octopus UI.
210
+
*`categories` is an array containing one or more step categories display by the Octopus UI where the step will be listed.
211
+
*`canRunOnDeploymentTarget` can be set to `true` to run the step on a target accessible via a tentacle, or `false` to be run on a worker.
212
+
*`launcher` defines how the step is executed. A value of `node` means the step is executed by Node.js.
213
+
214
+
### `inputs.ts`
215
+
216
+
This file performs the same function as it does when defining a new target.
217
+
218
+
An example is shown below exposing a single string field:
219
+
220
+
```typescript
221
+
exportdefaultinterfaceHelloWorldStepInputs {
222
+
name:string;
223
+
}
224
+
```
225
+
226
+
### `executor.ts`
227
+
228
+
The `executor.ts` file contains the logic to be executed when the step is run as part of a deployment process.
229
+
230
+
Unlike the function returned by the target `executor.ts` function, a step `executor.ts` function can receive inputs from both the step and the target. The combination of the inputs defined by these two resources allows a step executor to perform a common action on multiple targets.
231
+
232
+
For this example we print the greeting defined in the target and the name defined on the step to the output log:
The step form to be displayed by the Octopus web UI is defined the same was it was with the target. There is one small difference though, where the first parameter to the `createInitialInputs` function can be an instance of `InitialInputFactories`, which provides the ability to create blank package references.
253
+
254
+
Here we define the initial value of the `name` input to be a blank string, and build the form with a single `text` input:
0 commit comments