diff --git a/packages/nx/src/internal-testing-utils/temp-fs.ts b/packages/nx/src/internal-testing-utils/temp-fs.ts index b1029c47a7..be4b230b7d 100644 --- a/packages/nx/src/internal-testing-utils/temp-fs.ts +++ b/packages/nx/src/internal-testing-utils/temp-fs.ts @@ -105,12 +105,30 @@ export class TempFs { } cleanup() { - rmSync(this.tempDir, { recursive: true, force: true }); - setWorkspaceRoot(this.previousWorkspaceRoot); + try { + rmSync(this.tempDir, { recursive: true, force: true, maxRetries: 5 }); + setWorkspaceRoot(this.previousWorkspaceRoot); + } catch (e) { + // We are experiencing flakiness in CI related to this cleanup, so log only for now + if (process.env.CI) { + console.error(`Failed to cleanup temp dir: ${e}`); + } else { + throw e; + } + } } reset() { - rmSync(this.tempDir, { recursive: true, force: true }); - mkdirSync(this.tempDir, { recursive: true }); + try { + rmSync(this.tempDir, { recursive: true, force: true, maxRetries: 5 }); + mkdirSync(this.tempDir, { recursive: true }); + } catch (e) { + // We are experiencing flakiness in CI related to this cleanup, so log only for now + if (process.env.CI) { + console.error(`Failed to cleanup temp dir: ${e}`); + } else { + throw e; + } + } } }