Warm tip: This article is reproduced from stackoverflow.com, please click
github github-actions

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

发布于 2020-04-07 10:13:35

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?

Questioner
gosua
Viewed
53
DannyB 2020-02-03 03:26

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.