gosua
gosua

Reputation: 1067

What's the purpose of the environment variable CI set to true within a Github workflow?

Let's take this workflow as an example which is based on the NodeJS starter workflow.

name: continues integration workflow
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: checkout repo
      uses: actions/checkout@v2
    - name: setup node
      uses: actions/setup-node@v1
      with:
        node-version: '13.x'
    - run: npm test
      env:
        CI: true

What is the purpose of setting CI: true?

Upvotes: 7

Views: 3938

Answers (2)

VonC
VonC

Reputation: 1327544

Note that since April 2020, you will not see anymore

env:
  CI: true

That is because CI is now always set to true, by default.

As noted, this will allow for a script to check if it is running within the context of a CI/CD environment. You find the same convention in GitLab

Mark that job is executed in CI environment

Upvotes: 7

DannyB
DannyB

Reputation: 14816

As far as I can tell, the CI variable is there for compatibility with other CI systems. Here are the facts as I know them:

  1. GitHub Actions itself, does not have any use or need for the CI variable.
  2. Other CI systems - like Travis and CircleCI - always set CI=1.
  3. Unlike other systems, GitHub Actions does not set CI=true, since it is not intended for CI only. Instead, it sets GITHUB_ACTIONS=true.
  4. The conventional use for the CI variable, is so that your tests and app configuration can check for its existence, and do something differently if they need to (for example, skip certain tests on CI, or configure a different setting when on CI).

If your code and test code do not have the CI variable in them, then you can probably omit this setting and have the same result.

Upvotes: 5

Related Questions