gitlab-ci/cd(五)设置变量

定义变量的方式:

  • 在.gitlab-ci.yml文件中定义
  • pipeline中预定义的变量
  • 设置在项目中设置的变量

1、. gitlab-ci.yml 定义变量

variables:
  DEPLOY_VARIABLE: "default-deploy"
job1:
  variables:
    DEPLOY_VARIABLE: "job1-default-deploy"
  script:
    - echo "Run script with $DEPLOY_VARIABLE as an argument"
job2:
  script:
    - echo "Run script with $DEPLOY_VARIABLE as an argument"

2、项目中添加变量

project>>settings>>”CI/CD”>>Variables>>”Expand”

GitOps、新兴技术能力gitlab-ci/cd(五)设置变量插图
GitOps、新兴技术能力gitlab-ci/cd(五)设置变量插图1

3、CI/CD预定义的变量

https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

4、把所有变量列出

job_name:
  script:
    - export