<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Where variables can be used > 原文:[https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html](https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html) * [Variables usage](#variables-usage) * [`.gitlab-ci.yml` file](#gitlab-ciyml-file) * [`config.toml` file](#configtoml-file) * [Expansion mechanisms](#expansion-mechanisms) * [GitLab internal variable expansion mechanism](#gitlab-internal-variable-expansion-mechanism) * [GitLab Runner internal variable expansion mechanism](#gitlab-runner-internal-variable-expansion-mechanism) * [Execution shell environment](#execution-shell-environment) * [Persisted variables](#persisted-variables) * [Variables with an environment scope](#variables-with-an-environment-scope) # Where variables can be used[](#where-variables-can-be-used "Permalink") 如[CI / CD 變量](README.html)文檔中所述,您可以定義許多不同的變量. 其中一些可用于所有 GitLab CI / CD 功能,但其中某些功能或多或少受到限制. 本文檔描述了在何處以及如何使用不同類型的變量. ## Variables usage[](#variables-usage "Permalink") 有兩個地方可以使用定義的變量. 在: 1. GitLab 端,位于`.gitlab-ci.yml` . 2. 跑步者方面,位于`config.toml` . ### `.gitlab-ci.yml` file[](#gitlab-ciyml-file "Permalink") | Definition | 可以擴大嗎? | 擴展地點 | Description | | --- | --- | --- | --- | | `environment:url` | yes | GitLab | 變量擴展由 GitLab 的[內部變量擴展機制完成](#gitlab-internal-variable-expansion-mechanism) . 支持為作業定義的所有變量(項目/組變量, `.gitlab-ci.yml`中的變量,觸發器中的變量,管道計劃中的變量). 不支持在 Runner 的`config.toml`定義的變量和在 job 的`script`創建的變量. | | `environment:name` | yes | GitLab | 與`environment:url`相似,但是變量擴展不支持以下內容: -基于環境名稱的變量( `CI_ENVIRONMENT_NAME` , `CI_ENVIRONMENT_SLUG` ). -與環境相關的任何其他變量(當前僅`CI_ENVIRONMENT_URL` ). - [持久變量](#persisted-variables) . | | `resource_group` | yes | GitLab | 與`environment:url`相似,但是變量擴展不支持以下內容: -基于環境名稱的變量( `CI_ENVIRONMENT_NAME` , `CI_ENVIRONMENT_SLUG` ). -與環境相關的任何其他變量(當前僅`CI_ENVIRONMENT_URL` ). - [持久變量](#persisted-variables) . | | `variables` | yes | Runner | 變量擴展由 GitLab Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `image` | yes | Runner | 變量擴展由 GitLab Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `services:[]` | yes | Runner | 變量擴展由 GitLab Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `services:[]:name` | yes | Runner | 變量擴展由 GitLab Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `cache:key` | yes | Runner | 變量擴展由 GitLab Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `artifacts:name` | yes | Runner | 變量擴展由 GitLab Runner 的外殼環境完成 | | `script`, `before_script`, `after_script` | yes | 腳本執行外殼 | 變量擴展由[執行外殼環境進行](#execution-shell-environment) | | `only:variables:[]`, `except:variables:[]` | no | n/a | 變量必須采用`$variable`的形式. 以下不支持: -基于環境名稱的變量( `CI_ENVIRONMENT_NAME` , `CI_ENVIRONMENT_SLUG` ). -與環境相關的任何其他變量(當前僅`CI_ENVIRONMENT_URL` ). - [持久變量](#persisted-variables) . | ### `config.toml` file[](#configtoml-file "Permalink") **注意:**您可以在[Runner 的 docs 中](https://docs.gitlab.com/runner/configuration/advanced-configuration.html)閱讀有關`config.toml`更多信息. | Definition | 可以擴大嗎? | Description | | --- | --- | --- | | `runners.environment` | yes | 變量擴展由 Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `runners.kubernetes.pod_labels` | yes | 變量擴展由 Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | | `runners.kubernetes.pod_annotations` | yes | 變量擴展由 Runner 的[內部變量擴展機制完成](#gitlab-runner-internal-variable-expansion-mechanism) | ## Expansion mechanisms[](#expansion-mechanisms "Permalink") 共有三種擴展機制: * GitLab * 亞搏體育 app Runner * 執行外殼環境 ### GitLab internal variable expansion mechanism[](#gitlab-internal-variable-expansion-mechanism "Permalink") 擴展部分需要采用`$variable`或`${variable}`或`%variable%` . 每種格式都以相同的方式處理,無論最終由哪個 OS / shell 處理,因為擴展是在任何 Runner 獲得該工作之前在 GitLab 中完成的. ### GitLab Runner internal variable expansion mechanism[](#gitlab-runner-internal-variable-expansion-mechanism "Permalink") * 支持:項目/組變量, `.gitlab-ci.yml`變量, `config.toml`變量以及觸發器,管道計劃和手動管道中的變量. * 不支持:在腳本內部定義的變量(例如, `export MY_VARIABLE="test"` ). 跑步者使用 Go 的`os.Expand()`方法進行變量擴展. 這意味著它將僅處理定義為`$variable`和`${variable}` . 同樣重要的是,擴展只能執行一次,因此嵌套變量可能會或可能不會起作用,這取決于變量定義的順序. ### Execution shell environment[](#execution-shell-environment "Permalink") 這是`script`執行期間發生的擴展. 它的工作方式取決于所使用的 shell( `bash` , `sh` , `cmd` ,PowerShell). 例如,如果作業的`script`包含行`echo $MY_VARIABLE-${MY_VARIABLE_2}` ,則應由 bash / sh 正確處理(保留空字符串或某些值,具體取決于是否定義了變量),但不適用于 Windows 的`cmd`或 PowerShell,因為這些外殼使用不同的變量語法. Supported: * 該`script`可以使用外殼默認的所有可用變量(例如,應在所有 bash / sh 外殼中包含的`$PATH` )以及 GitLab CI / CD 定義的所有變量(項目/組變量, `.gitlab-ci.yml`變量, `config.toml`變量以及觸發器和管道計劃中的變量). * 該`script`還可以使用前面各行中定義的所有變量. 因此,例如,如果您定義變量`export MY_VARIABLE="test"` : * 在`before_script` ,這將在以下幾行工作`before_script`和相關的所有行`script` . * 在`script` ,它將在以下`script`行中工作. * 在`after_script` ,它將在`after_script`以下行中`after_script` . 對于`after_script`腳本,它們可以: * 僅在同一`after_script`部分中使用在腳本之前定義的變量. * 不要使用在`before_script`和`script`定義的變量. 這些限制是因為`after_script`腳本在[單獨的 shell 上下文](../yaml/README.html#before_script-and-after_script)中執行. ## Persisted variables[](#persisted-variables "Permalink") **注意:**一些持久變量包含令牌,由于安全原因,某些定義不能使用它們. 以下變量稱為"持久": * `CI_PIPELINE_ID` * `CI_JOB_ID` * `CI_JOB_TOKEN` * `CI_BUILD_ID` * `CI_BUILD_TOKEN` * `CI_REGISTRY_USER` * `CI_REGISTRY_PASSWORD` * `CI_REPOSITORY_URL` * `CI_DEPLOY_USER` * `CI_DEPLOY_PASSWORD` 他們是: * 支持["擴展位置"](#gitlab-ciyml-file)為的定義: * 賽跑者. * 腳本執行外殼. * 不支持: * 對于["擴展位置"](#gitlab-ciyml-file)是 GitLab 的定義. * 在`only`和`except` [變量表達式中](README.html#environment-variables-expressions) . ## Variables with an environment scope[](#variables-with-an-environment-scope "Permalink") 支持使用環境范圍定義的變量. 鑒于在`review/staging/*`范圍內定義了一個變量`$STAGING_SECRET` ,將基于匹配的變量表達式創建以下使用動態環境的作業: ``` my-job: stage: staging environment: name: review/$CI_JOB_STAGE/deploy script: - 'deploy staging' only: variables: - $STAGING_SECRET == 'something' ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看