-
Notifications
You must be signed in to change notification settings - Fork 6
/
yamlPatch.ts
33 lines (28 loc) · 1.01 KB
/
yamlPatch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as tl from "azure-pipelines-task-lib/task";
import patchProcess = require("./common/patchProcess");
import yamlPatcher = require("./yamlPatcher");
import { Operation } from "fast-json-patch";
var targetPath = tl.getPathInput("YamlWorkingDir");
var patchContent = tl.getInput("YamlPatchContent");
var patterns: any = tl.getInput("YamlTargetFilters");
var outputPatchedFile = tl.getBoolInput("OutputPatchFile");
var failIfNoPatchApplied = tl.getBoolInput("FailIfNoPatchApplied");
var treatErrors = tl.getInput("TreatErrors");
var syntax = tl.getInput("SyntaxType");
try {
var patches: Operation[] =
syntax == "slick"
? patchProcess.expandVariablesAndParseSlickPatch(patchContent)
: patchProcess.expandVariablesAndParseJson(patchContent);
patchProcess.apply(
new yamlPatcher.YamlPatcher(patches),
targetPath,
patterns,
outputPatchedFile,
failIfNoPatchApplied,
treatErrors
);
} catch (err) {
console.error(String(err));
tl.setResult(tl.TaskResult.Failed, String(err));
}