diff --git a/README.md b/README.md index 9516432..7de6961 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,9 @@ If you want to use tokens in XML based configuration files to be replaced during - replace tokens in your updated configuration file ## Release notes +**New in 3.5.1** +- Fix issue when variable `System.ServerType` is not defined ([#147](https://github.com/qetza/vsts-replacetokens-task/issues/147)). + **New in 3.5.0** - Add anonymous usage telemetry. - Ignore spaces between token prefix/suffix and variable name ([#143](https://github.com/qetza/vsts-replacetokens-task/issues/143)). diff --git a/make.js b/make.js index b901b99..6d125f9 100644 --- a/make.js +++ b/make.js @@ -190,8 +190,11 @@ updateTelemetryScript = function(instrumentationKey, taskVersion) { var scriptPath = path.join(binariesPath, 'task', 'telemetry.js'); var script = fs.readFileSync(scriptPath, { encoding: 'utf8' }); + if (instrumentationKey) script = script.replace(/const\s+instrumentationKey\s*=\s*'[^']*'\s*;/, "const instrumentationKey = '" + instrumentationKey + "';") - script = script.replace(/const\s+version\s*=\s*'[^']*'\s*;/, "const version = '" + taskVersion + "';"); + + if (taskVersion) + script = script.replace(/const\s+version\s*=\s*'[^']*'\s*;/, "const version = '" + taskVersion + "';"); fs.writeFileSync(scriptPath, script); } \ No newline at end of file diff --git a/task/index.ts b/task/index.ts index 0b00351..9ca0a03 100644 --- a/task/index.ts +++ b/task/index.ts @@ -394,7 +394,7 @@ var normalize = function (p: string): string { async function run() { let startTime: Date = new Date(); - let serverType = tl.getVariable('System.ServerType').toLowerCase(); + let serverType = tl.getVariable('System.ServerType'); let telemetryEnabled = tl.getBoolInput('enableTelemetry', true) && tl.getVariable('REPLACETOKENS_DISABLE_TELEMETRY') !== 'true'; let proxyUrl: string = undefined; @@ -406,7 +406,7 @@ async function run() { account: crypto.createHash('sha256').update(tl.getVariable('system.collectionid')).digest('hex'), pipeline: crypto.createHash('sha256').update(tl.getVariable('system.teamprojectid') + tl.getVariable('system.definitionid')).digest('hex'), pipelineType: tl.getVariable('release.releaseid') ? 'release' : 'build', - serverType: !serverType || serverType !== 'hosted' ? 'server' : 'services', + serverType: !serverType || serverType.toLowerCase() !== 'hosted' ? 'server' : 'services', } as TelemetryEvent; try { diff --git a/task/task.json b/task/task.json index b46ff98..6000644 100644 --- a/task/task.json +++ b/task/task.json @@ -13,7 +13,7 @@ "version": { "Major": 3, "Minor": 5, - "Patch": 0 + "Patch": 1 }, "instanceNameFormat": "Replace tokens in $(targetFiles)", "minimumAgentVersion": "2.105.0", diff --git a/vss-extension.json b/vss-extension.json index 8705810..779c2d7 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "id": "replacetokens", "name": "Replace Tokens", - "version": "3.5.0", + "version": "3.5.1", "public": true, "publisher": "qetza", "targets": [