@@ -150,9 +150,28 @@ export const EnvironmentVariableNames = {
150150 *
151151 * This is useful for testing purposes, or for OSS repos that are have a local-only cache, but can have
152152 * a different cache configuration in CI/CD pipelines.
153+ *
154+ * @remarks
155+ * This is similar to {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH}, but it allows you to specify
156+ * a JSON string instead of a file path. The two environment variables are mutually exclusive, meaning you can
157+ * only use one of them at a time.
153158 */
154159 RUSH_BUILD_CACHE_OVERRIDE_JSON : 'RUSH_BUILD_CACHE_OVERRIDE_JSON' ,
155160
161+ /**
162+ * Set this environment variable to the path to a `build-cache.json` file to override the build cache configuration
163+ * that normally lives at `common/config/rush/build-cache.json`.
164+ *
165+ * This is useful for testing purposes, or for OSS repos that are have a local-only cache, but can have
166+ * a different cache configuration in CI/CD pipelines.
167+ *
168+ * @remarks
169+ * This is similar to {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_OVERRIDE_JSON}, but it allows you to specify
170+ * a file path instead of a JSON string. The two environment variables are mutually exclusive, meaning you can
171+ * only use one of them at a time.
172+ */
173+ RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH : 'RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH' ,
174+
156175 /**
157176 * Setting this environment variable opts into running with cobuilds. The context id should be the same across
158177 * multiple VMs, but changed when it is a new round of cobuilds.
@@ -261,6 +280,8 @@ export class EnvironmentConfiguration {
261280
262281 private static _buildCacheOverrideJson : string | undefined ;
263282
283+ private static _buildCacheOverrideJsonFilePath : string | undefined ;
284+
264285 private static _cobuildContextId : string | undefined ;
265286
266287 private static _cobuildRunnerId : string | undefined ;
@@ -380,6 +401,15 @@ export class EnvironmentConfiguration {
380401 return EnvironmentConfiguration . _buildCacheOverrideJson ;
381402 }
382403
404+ /**
405+ * If set, overrides the build cache configuration that normally lives at `common/config/rush/build-cache.json`.
406+ * See {@link EnvironmentVariableNames.RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH}
407+ */
408+ public static get buildCacheOverrideJsonFilePath ( ) : string | undefined {
409+ EnvironmentConfiguration . _ensureValidated ( ) ;
410+ return EnvironmentConfiguration . _buildCacheOverrideJsonFilePath ;
411+ }
412+
383413 /**
384414 * Provides a determined cobuild context id if configured
385415 * See {@link EnvironmentVariableNames.RUSH_COBUILD_CONTEXT_ID}
@@ -542,6 +572,11 @@ export class EnvironmentConfiguration {
542572 break ;
543573 }
544574
575+ case EnvironmentVariableNames . RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH : {
576+ EnvironmentConfiguration . _buildCacheOverrideJsonFilePath = value ;
577+ break ;
578+ }
579+
545580 case EnvironmentVariableNames . RUSH_COBUILD_CONTEXT_ID : {
546581 EnvironmentConfiguration . _cobuildContextId = value ;
547582 break ;
@@ -603,6 +638,17 @@ export class EnvironmentConfiguration {
603638 ) ;
604639 }
605640
641+ if (
642+ EnvironmentConfiguration . _buildCacheOverrideJsonFilePath &&
643+ EnvironmentConfiguration . _buildCacheOverrideJson
644+ ) {
645+ throw new Error (
646+ `Environment variable ${ EnvironmentVariableNames . RUSH_BUILD_CACHE_OVERRIDE_JSON_FILE_PATH } and ` +
647+ `${ EnvironmentVariableNames . RUSH_BUILD_CACHE_OVERRIDE_JSON } are mutually exclusive. ` +
648+ `Only one may be specified.`
649+ ) ;
650+ }
651+
606652 // See doc comment for EnvironmentConfiguration._getRushGlobalFolderOverride().
607653 EnvironmentConfiguration . _rushGlobalFolderOverride =
608654 EnvironmentConfiguration . _getRushGlobalFolderOverride ( process . env ) ;
0 commit comments