Skip to content

Commit 72c3464

Browse files
Fix MSDO_PACKAGES_DIRECTORY initialization in cases where the CLI is not installed from the nuget server
1 parent fa0f8ba commit 72c3464

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

src/msdo-client.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ async function setupEnvironment(): Promise<void> {
2424

2525
console.log('------------------------------------------------------------------------------');
2626

27+
// initialize the _msdo directory
28+
let agentDirectory = path.join(process.env.AGENT_ROOTDIRECTORY, '_msdo');
29+
tl.debug(`agentDirectory = ${agentDirectory}`);
30+
common.ensureDirectory(agentDirectory);
31+
32+
let agentPackagesDirectory = process.env.MSDO_PACKAGES_DIRECTORY;
33+
if (!agentPackagesDirectory) {
34+
agentPackagesDirectory = path.join(agentDirectory, 'packages');
35+
tl.debug(`agentPackagesDirectory = ${agentPackagesDirectory}`);
36+
common.ensureDirectory(agentPackagesDirectory);
37+
process.env.MSDO_PACKAGES_DIRECTORY = agentPackagesDirectory;
38+
}
39+
2740
if (!process.env.MSDO_FILEPATH) {
2841
let cliVersion = resolveCliVersion();
2942
await installer.install(cliVersion);
@@ -81,6 +94,23 @@ async function init() {
8194
}
8295
}
8396

97+
/**
98+
* Runs "guardian update" to ensure the Guardian CLI is updated.
99+
*/
100+
async function update() {
101+
console.log('Updating CLI...');
102+
try {
103+
let cliFilePath = getCliFilePath();
104+
let tool = tl.tool(cliFilePath).arg('update');
105+
await tool.exec();
106+
console.log('Update complete.');
107+
}
108+
catch (error) {
109+
console.log('Something went wrong while updating the CLI. Continuing...');
110+
tl.debug(error);
111+
}
112+
}
113+
84114
/**
85115
* Runs "guardian run" with the input CLI arguments
86116
* @param inputArgs - The CLI arguments to pass to "guardian run"
@@ -89,6 +119,7 @@ async function init() {
89119
export async function run(inputArgs: string[], successfulExitCodes: number[] = null, publish: boolean = true, publishArtifactName: string = null, telemetryEnvironment: string = 'azdevops'): Promise<void> {
90120
let tool = null;
91121
let debugDrop = common.parseBool(process.env.GDN_DEBUG_DROP);
122+
let prerel = common.parseBool(process.env.MSDO_PRERELEASE);
92123

93124
let sarifFile: string = path.join(process.env.BUILD_STAGINGDIRECTORY, '.gdn', 'msdo.sarif');
94125
tl.debug(`sarifFile = ${sarifFile}`);
@@ -113,6 +144,10 @@ export async function run(inputArgs: string[], successfulExitCodes: number[] = n
113144

114145
await setupEnvironment();
115146
await init();
147+
if (prerel) {
148+
await update();
149+
await init();
150+
}
116151

117152
let cliFilePath = getCliFilePath();
118153

src/msdo-installer.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,7 @@ export async function install(cliVersion: string): Promise<void> {
3131

3232
let packageName = resolvePackageName();
3333

34-
// initialize the _msdo directory
3534
let agentDirectory = path.join(process.env.AGENT_ROOTDIRECTORY, '_msdo');
36-
tl.debug(`agentDirectory = ${agentDirectory}`);
37-
common.ensureDirectory(agentDirectory);
38-
39-
let agentPackagesDirectory = process.env.MSDO_PACKAGES_DIRECTORY;
40-
if (!agentPackagesDirectory) {
41-
agentPackagesDirectory = path.join(agentDirectory, 'packages');
42-
tl.debug(`agentPackagesDirectory = ${agentPackagesDirectory}`);
43-
common.ensureDirectory(agentPackagesDirectory);
44-
process.env.MSDO_PACKAGES_DIRECTORY = agentPackagesDirectory;
45-
}
46-
4735
let agentVersionsDirectory = path.join(agentDirectory, 'versions');
4836
tl.debug(`agentVersionsDirectory = ${agentVersionsDirectory}`);
4937
common.ensureDirectory(agentVersionsDirectory);

0 commit comments

Comments
 (0)