diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index be73bfcef4b31..61484f3705e26 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -353,3 +353,10 @@ Some of the interesting keys that can be used in the JSON configuration files: "versionReporting": false, // Opt-out of version reporting (--no-version-reporting) } ``` + +#### Environment + +The following environment variables affect aws-cdk: + +- `CDK_DISABLE_VERSION_CHECK`: If set, disable automatic check for newer versions. +- `CDK_NEW_BOOTSTRAP`: use the modern bootstrapping stack. diff --git a/packages/aws-cdk/lib/version.ts b/packages/aws-cdk/lib/version.ts index fecbe1c0e1886..19bec86549c2e 100644 --- a/packages/aws-cdk/lib/version.ts +++ b/packages/aws-cdk/lib/version.ts @@ -98,7 +98,7 @@ export async function latestVersionIfHigher(currentVersion: string, cacheFile: V } export async function displayVersionMessage(): Promise { - if (!process.stdout.isTTY) { + if (!process.stdout.isTTY || process.env.CDK_DISABLE_VERSION_CHECK) { return; } diff --git a/packages/aws-cdk/test/version.test.ts b/packages/aws-cdk/test/version.test.ts index 005ccd209e609..49ddb4b12aa8d 100644 --- a/packages/aws-cdk/test/version.test.ts +++ b/packages/aws-cdk/test/version.test.ts @@ -3,7 +3,8 @@ import { setTimeout as _setTimeout } from 'timers'; import { promisify } from 'util'; import * as fs from 'fs-extra'; import * as sinon from 'sinon'; -import { latestVersionIfHigher, VersionCheckTTL } from '../lib/version'; +import * as logging from '../lib/logging'; +import { latestVersionIfHigher, VersionCheckTTL, displayVersionMessage } from '../lib/version'; const setTimeout = promisify(_setTimeout); @@ -72,3 +73,11 @@ test('No Version specified for storage in the TTL file', async () => { const storedVersion = fs.readFileSync(cacheFile, 'utf8'); expect(storedVersion).toBe(''); }); + +test('Skip version check if environment variable is set', async () => { + process.stdout.isTTY = true; + process.env.CDK_DISABLE_VERSION_CHECK = '1'; + const printStub = sinon.stub(logging, 'print'); + await displayVersionMessage(); + expect(printStub.called).toEqual(false); +});