azure-pipelines-tasks-webdeployment-common 4.247.0 → 4.253.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -154,14 +154,18 @@ function enhancedFileTransformations(isFolderBasedDeployment, xmlTransformation,
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
isSubstitutionApplied = true;
|
|
157
|
+
let InputErrors = tl.getBoolInput('errorOnInvalidSubstitution', false);
|
|
157
158
|
if (jsonTargetFiles.length > 0) {
|
|
158
159
|
isSubstitutionApplied = jsonSubstitutionUtility.jsonVariableSubstitution(folderPath, jsonTargetFiles, true);
|
|
159
160
|
if (isSubstitutionApplied) {
|
|
160
161
|
console.log(tl.loc('JSONvariablesubstitutionappliedsuccessfully'));
|
|
161
162
|
}
|
|
162
|
-
else {
|
|
163
|
+
else if (InputErrors) {
|
|
163
164
|
throw Error(tl.loc('FailedToApplyJSONvariablesubstitutionReason1'));
|
|
164
165
|
}
|
|
166
|
+
else {
|
|
167
|
+
tl.error(tl.loc('FailedToApplyJSONvariablesubstitutionReason1'));
|
|
168
|
+
}
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
exports.enhancedFileTransformations = enhancedFileTransformations;
|
|
@@ -167,6 +167,7 @@ exports.stripJsonComments = stripJsonComments;
|
|
|
167
167
|
function jsonVariableSubstitution(absolutePath, jsonSubFiles, substituteAllTypes) {
|
|
168
168
|
var envVarObject = createEnvTree(tl.getVariables());
|
|
169
169
|
let isSubstitutionApplied = false;
|
|
170
|
+
let emptyFiles = [];
|
|
170
171
|
for (let jsonSubFile of jsonSubFiles) {
|
|
171
172
|
console.log(tl.loc('JSONvariableSubstitution', jsonSubFile));
|
|
172
173
|
var matchFiles = utility.findfiles(path.join(absolutePath, jsonSubFile));
|
|
@@ -174,29 +175,38 @@ function jsonVariableSubstitution(absolutePath, jsonSubFiles, substituteAllTypes
|
|
|
174
175
|
throw new Error(tl.loc('NOJSONfilematchedwithspecificpattern', jsonSubFile));
|
|
175
176
|
}
|
|
176
177
|
for (let file of matchFiles) {
|
|
178
|
+
console.log("Processing file: " + file);
|
|
177
179
|
var fileBuffer = fs.readFileSync(file);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
180
|
+
if (fileBuffer.length > 4) {
|
|
181
|
+
var fileEncodeType = fileEncoding.detectFileEncoding(file, fileBuffer);
|
|
182
|
+
var fileContent = fileBuffer.toString(fileEncodeType[0]);
|
|
183
|
+
if (fileEncodeType[1]) {
|
|
184
|
+
fileContent = fileContent.slice(1);
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
fileContent = stripJsonComments(fileContent);
|
|
188
|
+
var jsonObject = JSON.parse(fileContent);
|
|
189
|
+
}
|
|
190
|
+
catch (exception) {
|
|
191
|
+
throw Error(tl.loc('JSONParseError', file, exception));
|
|
192
|
+
}
|
|
193
|
+
console.log(tl.loc('JSONvariableSubstitution', file));
|
|
194
|
+
if (substituteAllTypes) {
|
|
195
|
+
isSubstitutionApplied = substituteJsonVariableV2(jsonObject, envVarObject) || isSubstitutionApplied;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
isSubstitutionApplied = substituteJsonVariable(jsonObject, envVarObject) || isSubstitutionApplied;
|
|
199
|
+
}
|
|
200
|
+
tl.writeFile(file, (fileEncodeType[1] ? '\uFEFF' : '') + JSON.stringify(jsonObject, null, 4), fileEncodeType[0]);
|
|
193
201
|
}
|
|
194
202
|
else {
|
|
195
|
-
|
|
203
|
+
emptyFiles.push(file);
|
|
196
204
|
}
|
|
197
|
-
tl.writeFile(file, (fileEncodeType[1] ? '\uFEFF' : '') + JSON.stringify(jsonObject, null, 4), fileEncodeType[0]);
|
|
198
205
|
}
|
|
199
206
|
}
|
|
207
|
+
if (emptyFiles.length > 0) {
|
|
208
|
+
console.log(`The following input files either empty: ${emptyFiles.join(', ')}. No substitution was performed.`);
|
|
209
|
+
}
|
|
200
210
|
return isSubstitutionApplied;
|
|
201
211
|
}
|
|
202
212
|
exports.jsonVariableSubstitution = jsonVariableSubstitution;
|