@@ -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() {
89119export 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
0 commit comments