Skip to content

Commit 26b361d

Browse files
authored
fix(cli): cannot set environment variable CI=false (#32749)
We check the `$CI` environment variable for its presence, not for its value. This means that setting `CI=false` enables CI mode instead of disabling it. This is unexpected. Fix it. We could have checked for `CI=true` or `CI=1`, but the current behavior is backwards compatible with crazy things users might already be doing. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent bd38861 commit 26b361d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/aws-cdk/lib/util/yargs-helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function yargsNegativeAlias<T extends { [x in S | L]: boolean | undefined
2727
* @returns true if the current process is running in a CI environment
2828
*/
2929
export function isCI(): boolean {
30-
return process.env.CI !== undefined;
30+
return process.env.CI !== undefined && process.env.CI !== 'false' && process.env.CI !== '0';
3131
}
3232

3333
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isCI } from '../../lib/util/yargs-helpers';
2+
3+
test.each([
4+
['true', true],
5+
['1', true],
6+
['false', false],
7+
['0', false],
8+
// The following ones are unexpected but this is the legacy behavior we're preserving.
9+
['banana', true],
10+
['', true],
11+
])('test parsing of falsey CI values: %p parses as %p', (envvar, ci) => {
12+
process.env.CI = envvar;
13+
expect(isCI()).toEqual(ci);
14+
});

0 commit comments

Comments
 (0)