Have ideas to improve npm?Join in the discussion! »

    gitlab-ci-env

    3.7.0 • Public • Published

    GitLab CI Env

    GitLab CI Env returns an object containing all of the predefined environment variables provided by GitLab CI.

    Usage

    const gitlabEnv = require('gitlab-ci-env');
    
    const projectName = gitlabEnv.ci.project.name;
    const commitSha = gitlabEnv.ci.commit.sha;

    Variable Reference

    The GitLab predefined environment variables are grouped by function. Generally this hierarchy can be derived from the name, e.g. CI_COMMIT_REF_NAME and CI_COMMIT_REF_SLUG are provided via ci.commit.ref.name and ci.commit.ref.slug respectively. There are some exceptions, which are included as properties in the most appropriate functional location.

    A complete mapping of the GitLab predefined environment variables to the object provided by this module is given below for reference (values equal variable names).

    {
      chat: {
        channel: 'CHAT_CHANNEL',
        input: 'CHAT_INPUT',
      },
      ci: {
        author: 'CI_COMMIT_AUTHOR',
        apiV4Url: 'CI_API_V4_URL',
        buildsDir: 'CI_BUILDS_DIR',
        commit: {
          beforeSha: 'CI_COMMIT_BEFORE_SHA',
          branch: 'CI_COMMIT_BRANCH',
          description: 'CI_COMMIT_DESCRIPTION',
          message: 'CI_COMMIT_MESSAGE',
          ref: {
            name: 'CI_COMMIT_REF_NAME',
            slug: 'CI_COMMIT_REF_SLUG',
          },
          refProtected: 'CI_COMMIT_REF_PROTECTED',
          sha: 'CI_COMMIT_SHA',
          shortSha: 'CI_COMMIT_SHORT_SHA',
          tag: 'CI_COMMIT_TAG',
          timestamp: 'CI_COMMIT_TIMESTAMP',
          title: 'CI_COMMIT_TITLE',
        },
        concurrentID: 'CI_CONCURRENT_ID',
        concurrentProjectID: 'CI_CONCURRENT_PROJECT_ID',
        configPath: 'CI_CONFIG_PATH',
        debugTrace: 'CI_DEBUG_TRACE',
        defaultBranch: 'CI_DEFAULT_BRANCH',
        dependencyProxy: {
            groupImagePrefix: 'CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX',
            password: 'CI_DEPENDENCY_PROXY_PASSWORD',
            server: 'CI_DEPENDENCY_PROXY_SERVER',
            user: 'CI_DEPENDENCY_PROXY_USER'
        },
        deploy: {
          freeze: 'CI_DEPLOY_FREEZE',
          password: 'CI_DEPLOY_PASSWORD',
          user: 'CI_DEPLOY_USER',
        },
        environment: {
          isDisposable: 'CI_DISPOSABLE_ENVIRONMENT',
          name: 'CI_ENVIRONMENT_NAME',
          slug: 'CI_ENVIRONMENT_SLUG',
          url: 'CI_ENVIRONMENT_URL',
        },
        externalPullRequest: {
          iid: 'CI_EXTERNAL_PULL_REQUEST_IID',
          source: {
            branch: {
              sha: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_SHA',
              name: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_NAME'
            },
            repository: 'CI_EXTERNAL_PULL_REQUEST_SOURCE_REPOSITORY'
          },
          target: {
            branch: {
              sha: 'CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_SHA',
              name: 'CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME'
            },
            repository: 'CI_EXTERNAL_PULL_REQUEST_TARGET_REPOSITORY'
          }
        },
        hasOpenRequirements: 'CI_HAS_OPEN_REQUIREMENTS',
        isCI: 'CI',
        job: {
          id: 'CI_JOB_ID',
          image: 'CI_JOB_IMAGE',
          jwt: 'CI_JOB_JWT',
          manual: 'CI_JOB_MANUAL',
          name: 'CI_JOB_NAME',
          stage: 'CI_JOB_STAGE',
          startedAt: 'CI_JOB_STARTED_AT',
          status: 'CI_JOB_STATUS',
          token: 'CI_JOB_TOKEN',
          url: 'CI_JOB_URL',
        },
        kubernetesActive: 'CI_KUBERNETES_ACTIVE',
        mergeRequest: {
          assignees: 'CI_MERGE_REQUEST_ASSIGNEES',
          diff: {
              id: 'CI_MERGE_REQUEST_DIFF_ID',
              baseSha: 'CI_MERGE_REQUEST_DIFF_BASE_SHA'
          },
          eventType: 'CI_MERGE_REQUEST_EVENT_TYPE',
          id: 'CI_MERGE_REQUEST_ID',
          iid: 'CI_MERGE_REQUEST_IID',
          labels: 'CI_MERGE_REQUEST_LABELS',
          milestones: 'CI_MERGE_REQUEST_MILESTONE',
          project: {
            id: 'CI_MERGE_REQUEST_PROJECT_ID',
            path: 'CI_MERGE_REQUEST_PROJECT_PATH',
            url: 'CI_MERGE_REQUEST_PROJECT_URL',
          },
          refPath: 'CI_MERGE_REQUEST_REF_PATH',
          source: {
            branch: {
              name: 'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME',
              sha: 'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA',
              id: 'CI_MERGE_REQUEST_SOURCE_PROJECT_ID'
            },
            project: {
              path: 'CI_MERGE_REQUEST_SOURCE_PROJECT_PATH',
              url: 'CI_MERGE_REQUEST_SOURCE_PROJECT_URL'
            },
          },
          target: {
            branch: {
              name: 'CI_MERGE_REQUEST_TARGET_BRANCH_NAME',
              sha: 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA'
            },
          },
          title: 'CI_MERGE_REQUEST_TITLE',
        },
        node: {
          index: 'CI_NODE_INDEX',
          total: 'CI_NODE_TOTAL',
        },
        pages: {
          domain: 'CI_PAGES_DOMAIN',
          url: 'CI_PAGES_URL',
        },
        pipeline: {
          createdAt: 'CI_PIPELINE_CREATED_AT',
          id: 'CI_PIPELINE_ID',
          iid: 'CI_PIPELINE_IID',
          source: 'CI_PIPELINE_SOURCE',
          triggered: 'CI_PIPELINE_TRIGGERED',
          triggerPayload: 'TRIGGER_PAYLOAD',
          url: 'CI_PIPELINE_URL',
        },
        project: {
          configPath: 'CI_PROJECT_CONFIG_PATH',
          dir: 'CI_PROJECT_DIR',
          id: 'CI_PROJECT_ID',
          name: 'CI_PROJECT_NAME',
          namespace: 'CI_PROJECT_NAMESPACE',
          openMergeRequests: 'CI_OPEN_MERGE_REQUESTS',
          path: 'CI_PROJECT_PATH',
          pathSlug: 'CI_PROJECT_PATH_SLUG',
          repositoryLanguages: 'CI_PROJECT_REPOSITORY_LANGUAGES',
          rootNamespace: 'CI_PROJECT_ROOT_NAMESPACE',
          title: 'CI_PROJECT_TITLE',
          url: 'CI_PROJECT_URL',
          visibility: 'CI_PROJECT_VISIBILITY',
        },
        registry: {
          image: 'CI_REGISTRY_IMAGE',
          password: 'CI_REGISTRY_PASSWORD',
          registry: 'CI_REGISTRY',
          url: 'CI_REPOSITORY_URL',
          user: 'CI_REGISTRY_USER',
        },
        runner: {
          description: 'CI_RUNNER_DESCRIPTION',
          executableArch: 'CI_RUNNER_EXECUTABLE_ARCH',
          id: 'CI_RUNNER_ID',
          revision: 'CI_RUNNER_REVISION',
          shortToken: 'CI_RUNNER_SHORT_TOKEN',
          tags: 'CI_RUNNER_TAGS',
          version: 'CI_RUNNER_VERSION',
        },
        server: {
          host: 'CI_SERVER_HOST',
          isServer: 'CI_SERVER',
          name: 'CI_SERVER_NAME',
          port: 'CI_SERVER_PORT',
          protocol: 'CI_SERVER_PROTOCOL',
          revision: 'CI_SERVER_REVISION',
          url: 'CI_SERVER_URL',
          version: {
            major: 'CI_SERVER_VERSION_MAJOR',
            minor: 'CI_SERVER_VERSION_MINOR',
            patch: 'CI_SERVER_VERSION_PATCH',
            version: 'CI_SERVER_VERSION',
          },
        },
        sharedEnvironment: 'CI_SHARED_ENVIRONMENT',
      },
      gitlab: {
        features: 'GITLAB_FEATURES',
        isCI: 'GITLAB_CI',
        user: {
          email: 'GITLAB_USER_EMAIL',
          id: 'GITLAB_USER_ID',
          login: 'GITLAB_USER_LOGIN',
          name: 'GITLAB_USER_NAME',
        },
      },
    }

    A complete listing of the GitLab predefined environment variables with descriptions can be found at https://docs.gitlab.com/ee/ci/variables/predefined_variables.html.

    Install

    npm i gitlab-ci-env

    DownloadsWeekly Downloads

    160

    Version

    3.7.0

    License

    MIT

    Unpacked Size

    82.9 kB

    Total Files

    18

    Last publish

    Collaborators

    • avatar