From 47d28d6bf604bd116f970db38a2d0473be1dd419 Mon Sep 17 00:00:00 2001 From: sverdlov93 Date: Wed, 9 Feb 2022 12:41:50 +0200 Subject: [PATCH] improve env exclusion --- jfrog-tasks-utils/utils.js | 4 ++-- tasks/JFrogPublishBuildInfo/publishBuildInfo.js | 12 +++++++----- tests/resources/excludeEnv/upload.js | 2 ++ tests/resources/includeEnv/upload.js | 2 ++ tests/tests.ts | 8 +++++++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/jfrog-tasks-utils/utils.js b/jfrog-tasks-utils/utils.js index 22f17d6b..6d49c10c 100644 --- a/jfrog-tasks-utils/utils.js +++ b/jfrog-tasks-utils/utils.js @@ -381,11 +381,11 @@ function cliJoin(...args) { } function quote(str) { - return '"' + str + '"'; + return str ? '"' + str + '"' : ""; } function singleQuote(str) { - return "'" + str + "'"; + return str ? "'" + str + "'" : ""; } function addStringParam(cliCommand, inputParam, cliParam, require) { diff --git a/tasks/JFrogPublishBuildInfo/publishBuildInfo.js b/tasks/JFrogPublishBuildInfo/publishBuildInfo.js index 231889f6..afd056bc 100644 --- a/tasks/JFrogPublishBuildInfo/publishBuildInfo.js +++ b/tasks/JFrogPublishBuildInfo/publishBuildInfo.js @@ -23,7 +23,7 @@ function RunTaskCbk(cliPath) { cliBuildPublishCommand, utils.quote(buildName), utils.quote(buildNumber), - '--env-exclude=' + utils.quote(excludeEnvVars) + excludeEnvVars ? '--env-exclude=' + utils.quote(excludeEnvVars) : "" ); cliCommand = addBuildUrl(cliCommand); cliCommand = utils.addProjectOption(cliCommand); @@ -59,11 +59,13 @@ function attachBuildInfoUrl(buildName, buildNumber, workDir) { function addBuildUrl(cliCommand) { let collectionUri = tl.getVariable('System.TeamFoundationCollectionUri'); let projectName = tl.getVariable('System.TeamProject'); - let buildId = tl.getVariable('Build.BuildId'); - let releaseId = tl.getVariable('Release.ReleaseId'); + if (collectionUri && projectName) { + let buildId = tl.getVariable('Build.BuildId'); + let releaseId = tl.getVariable('Release.ReleaseId'); - let buildUrl = collectionUri + projectName + '/_' + (releaseId ? 'release?releaseId=' + releaseId : 'build?buildId=' + buildId); - cliCommand = utils.cliJoin(cliCommand, '--build-url=' + utils.quote(buildUrl)); + let buildUrl = collectionUri + projectName + '/_' + (releaseId ? 'release?releaseId=' + releaseId : 'build?buildId=' + buildId); + cliCommand = utils.cliJoin(cliCommand, '--build-url=' + utils.quote(buildUrl)); + } return cliCommand; } diff --git a/tests/resources/excludeEnv/upload.js b/tests/resources/excludeEnv/upload.js index a63c4c7d..03786a82 100644 --- a/tests/resources/excludeEnv/upload.js +++ b/tests/resources/excludeEnv/upload.js @@ -9,6 +9,8 @@ let variables = { 'Build.DefinitionName': BUILD_NAME, 'Build.BuildNumber': BUILD_NUMBER, 'Build.password': 'open-sesame', + 'Build.token': 'open-sesame', + 'Build.secret': 'open-sesame', 'Build.undefined': 'undefined', 'Build.null': 'null' }; diff --git a/tests/resources/includeEnv/upload.js b/tests/resources/includeEnv/upload.js index b3517b50..2cc384e5 100644 --- a/tests/resources/includeEnv/upload.js +++ b/tests/resources/includeEnv/upload.js @@ -9,6 +9,8 @@ let variables = { 'Build.DefinitionName': BUILD_NAME, 'Build.BuildNumber': BUILD_NUMBER, 'Build.password': 'open-sesame', + 'Build.token': 'open-sesame', + 'Build.secret': 'open-sesame', 'Build.undefined': 'undefined', 'Build.null': 'null' }; diff --git a/tests/tests.ts b/tests/tests.ts index 26abeed7..45a0800f 100644 --- a/tests/tests.ts +++ b/tests/tests.ts @@ -373,7 +373,10 @@ describe('JFrog Artifactory Extension Tests', (): void => { assertBuildEnv(build, 'buildInfo.env.BUILD_BUILDNUMBER', '3'); assertBuildEnv(build, 'buildInfo.env.BUILD_UNDEFINED', 'undefined'); assertBuildEnv(build, 'buildInfo.env.BUILD_NULL', 'null'); - assertBuildEnv(build, 'buildInfo.env.BUILD_PASSWORD', 'open-sesame'); + // Default excluded by CLI (*password*;*psw*;*secret*;*key*;*token*;*auth*): + assertBuildEnv(build, 'buildInfo.env.BUILD_PASSWORD', undefined); + assertBuildEnv(build, 'buildInfo.env.BUILD_TOKEN', undefined); + assertBuildEnv(build, 'buildInfo.env.BUILD_SECRET', undefined); deleteBuild('includeEnv'); }, TestUtils.isSkipTest('generic') @@ -424,7 +427,10 @@ describe('JFrog Artifactory Extension Tests', (): void => { assertBuildEnv(build, 'buildInfo.env.BUILD_BUILDNUMBER', '3'); assertBuildEnv(build, 'buildInfo.env.BUILD_UNDEFINED', 'undefined'); assertBuildEnv(build, 'buildInfo.env.BUILD_NULL', 'null'); + // Only *password* should be excluded assertBuildEnv(build, 'buildInfo.env.BUILD_PASSWORD', undefined); + assertBuildEnv(build, 'buildInfo.env.BUILD_TOKEN', 'open-sesame'); + assertBuildEnv(build, 'buildInfo.env.BUILD_SECRET', 'open-sesame'); deleteBuild('excludeEnv'); }, TestUtils.isSkipTest('generic')