Skip to content

Commit c2db0cd

Browse files
bcallaghan-etBen Callaghan
andauthored
fix(dotnet): expand env vars in cli parameters (#422)
Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
1 parent 40ab979 commit c2db0cd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/dotnet/src/lib/core/dotnet.client.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ describe('dotnet client', () => {
6565
`);
6666
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
6767
});
68+
69+
it('should expand environment variables', () => {
70+
process.env.FOO = 'bar';
71+
dotnetClient.publish(
72+
'my-project',
73+
undefined,
74+
undefined,
75+
'-p:Name=$FOO',
76+
);
77+
expect(spawnSyncSpy.mock.calls[0][1]).toContain('-p:Name=bar');
78+
});
6879
});
6980
});
7081
});

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ export class DotNetClient {
166166
}
167167

168168
private logAndExecute(params: string[]): void {
169+
params = params.map((param) =>
170+
param.replace(/\$(\w+)/, (match, varName) => process.env[varName] ?? ''),
171+
);
172+
169173
const cmd = `${this.cliCommand.command} "${params.join('" "')}"`;
170174
console.log(`Executing Command: ${cmd}`);
175+
171176
const res = spawnSync(this.cliCommand.command, params, {
172177
cwd: this.cwd || process.cwd(),
173178
stdio: 'inherit',

0 commit comments

Comments
 (0)