-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create var file for template variables #7511
Changes from 1 commit
89c6c2e
a929e1a
757713c
024bc0b
8018df5
a7703d9
6b84fb7
75fb3f3
4eb3fe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,17 @@ export function readJsonFile(filePath: string): string { | |
return content; | ||
} | ||
|
||
export function createTemplateVarFile (templateVariables: Map<string, string>): string { | ||
let filePath: string = path.resolve(tl.getVariable('Agent.TempDirectory'), Math.random().toString(36).replace('0.', '') + '.json'); | ||
let res = {}; | ||
templateVariables.forEach((value: string, key: string) => { | ||
res[key] = value | ||
}); | ||
let content: string = JSON.stringify(res); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please test with special characters in values - space, quotes etc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested this on ubuntu 18.04 and win 10. The var file created had whitespaces and quotes in its path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also test for variable values containing special chars. They should be properly escaped when using Json.Stringify and packer should be able to consume them successfully There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
tl.writeFile(filePath, content); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a writeFile utility which will be useful in l0 mocking |
||
return filePath | ||
} | ||
|
||
export function writeFile(filePath: string, content: string): void { | ||
tl.writeFile(filePath, content); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of random, you can also use Date.now() which is good enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using Date.now(), but since we create 2 separate var files one after the other, there were name collisions a few times. That is why I am using to Math.random.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok