プロジェクトの値と変数
このページでは、CircleCI プロジェクトで使用できる定義済みの値について説明します。
定義済み環境変数
下記の定義済み環境変数は、すべての CircleCI プロジェクトで使用できます。 環境変数はジョブレベルで設定されます。 一つのジョブのコンテキスト内では使用できますが、パイプラインレベルでは存在しないため、パイプラインレベルまたはワークフローレベルのロジックには使用できません。
環境変数はジョブレベルで設定されます。 一つのジョブのコンテキスト内では使用できますが、パイプラインレベルでは存在しないため、パイプラインレベルまたはワークフローレベルのロジックには使用できません。
注: 定義済み環境変数を使用して別の環境変数を定義することはできません。 代わりに、run`ステップを使用して、新しい環境変数を `BASH_ENV でエクスポートする必要があります。 詳しくは シェルコマンドで環境変数を設定するをご覧ください。 |
Variable | VCS | Type | Value | Cloud | Server |
---|---|---|---|---|---|
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Boolean |
| ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Boolean |
| ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The name of the Git branch currently being built. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Integer | The number of the current job. Job numbers are unique for each job. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The URL for the current job on CircleCI. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The name of the current job. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Integer | For jobs that run with parallelism enabled, this is the index of the current parallel run. The value ranges from 0 to ( | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Integer | For jobs that run with parallelism enabled, this is the number of parallel runs. This is equivalent to the value of | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | An OpenID Connect token signed by CircleCI which includes details about the current job. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | An OpenID Connect token signed by CircleCI which includes details about the current job. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | A unique identifier for the CircleCI organization. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | A unique identifier for the current pipeline. | ||
| GitHub OAuth, Bitbucket | Integer | The number of the associated GitHub or Bitbucket pull request. Only available on forked PRs. | ||
| GitHub OAuth, Bitbucket | String | The name of the GitHub or Bitbucket repository where the pull request was created. Only available on forked PRs. | ||
| GitHub OAuth, Bitbucket | String | The GitHub or Bitbucket username of the user who created the pull request. Only available on forked PRs. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | Integer | The largest job number in a given branch that is less than the current job number. Note: The variable is not always set, and is not deterministic. It is also not set on runner executors. This variable is likely to be deprecated, and CircleCI recommends users to avoid using it. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | A unique identifier for the current project. | ||
| GitHub OAuth, GitHub App, GitLab, Bitbucket | String | The name of the repository of the current project. | ||
| GitHub OAuth, GitHub App, GitLab, Bitbucket | String | The GitHub or Bitbucket username of the current project. | ||
| GitHub OAuth, Bitbucket | String | The URL of the associated pull request. If there are multiple associated pull requests, one URL is randomly chosen. | ||
| GitHub OAuth, Bitbucket | List | Comma-separated list of URLs of the current build’s associated pull requests. | ||
| GitHub OAuth, Bitbucket | String | The URL of your GitHub or Bitbucket repository. | ||
| GitHub OAuth, GitHub App, GitLab, Bitbucket | String | The SHA1 hash of the last commit of the current build. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The name of the git tag, if the current build is tagged. For more information, see the Git tag job execution section of the Workflows page. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The GitHub or Bitbucket username of the user who triggered the pipeline (only if the user has a CircleCI account). | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | A unique identifier for the workflow instance of the current job. This identifier is the same for every job in a given workflow instance. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | A unique identifier for the current job. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | An identifier for the workspace of the current job. This identifier is the same for every job in a given workflow. | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | The value of the | ||
| GitHub OAuth, GitHub App, Bitbucket, GitLab | String | Internal. A directory where internal data related to the job is stored. We do not document the contents of this directory; the data schema is subject to change. |
If you must use the environment variables that are deprecated for GitLab SaaS in your GitLab pipelines, you can recreate this functionality using pipeline values in your configuration file. The following example shows how to set an environment variable CIRCLE_PROJECT_REPONAME
using the environment
key and populating it with the pipeline.trigger_parameters.gitlab.repo_name
value:
build:
docker:
- image: cimg/node:17.0
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment:
CIRCLE_PROJECT_REPONAME: << pipeline.trigger_parameters.gitlab.repo_name >>
steps:
- run: echo $CIRCLE_PROJECT_REPONAME
パイプライン値
パイプライン値は、すべてのパイプライン設定で事前に宣言することなく使用できます。 パイプライン値はパイプラインレベルで設定されます。 ワークフローやジョブの実行時ではなく、コンパイル時に挿入されます。
Variable | Source | Type | Value | Cloud | Server |
---|---|---|---|---|---|
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | A globally unique id representing for the pipeline. | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | Integer | A project unique integer id for the pipeline. | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The URL where the current project is hosted. For example, | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The lower-case name of the VCS provider, for example, | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The name of the git tag that was pushed to trigger the pipeline. If the pipeline was not triggered by a tag, then this is the empty string. | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The name of the git branch that was pushed to trigger the pipeline. | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The long (40-character) git SHA that is being built. | ||
| GitHub OAuth, Bitbucket | String | The long (40-character) git SHA of the build prior to the one being built. Note: While in most cases | ||
| GitHub App, GitHub OAuth, Bitbucket, GitLab | String | The source that triggers the pipeline, current values are | ||
| GitHub OAuth, Bitbucket | String | The name of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggered by other sources. | ||
| GitHub OAuth, Bitbucket | String | The unique id of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggered by other sources. | ||
| GitHub App, GitLab | GitHub App, GitLab | |||
| GitHub App, GitLab | Timestamp CircleCI received the event | |||
| GitHub App, GitLab |
| |||
| GitHub App, GitLab | CircleCI project ID | |||
| GitHub App, GitLab | CircleCI user ID | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitHub App | See GitHub documentation for webhook events and payloads. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| GitLab | See GitLab documentation for webhooks and webhook events. | |||
| Inbound webhook | String | The body of the payload that was sent with an inbound webhook. |
たとえば以下のようになります。
version: 2.1
jobs:
build:
docker:
- image: cimg/node:20.3.0
environment:
CIRCLE_COMPARE_URL: << pipeline.project.git_url >>/compare/<< pipeline.git.base_revision >>..<<pipeline.git.revision>>
working_directory: ~/main
steps:
- run: echo "This is pipeline ID << pipeline.id >>"
- run: echo $CIRCLE_COMPARE_URL
上記の方法で environment キーの変数を設定する際にパイプラインの変数が空の場合、変数は <nil> が設定されます。 文字列を空にする必要がある場合は、 シェルコマンドで変数を設定するをご覧ください。