Skip to content

Commit

Permalink
improve env exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 committed Feb 9, 2022
1 parent 34dd3e0 commit 47d28d6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions jfrog-tasks-utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions tasks/JFrogPublishBuildInfo/publishBuildInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/resources/excludeEnv/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down
2 changes: 2 additions & 0 deletions tests/resources/includeEnv/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down
8 changes: 7 additions & 1 deletion tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 47d28d6

Please sign in to comment.