简体   繁体   English

如何在gitlab-ci.yml文件中使用变量

[英]How to use variables in gitlab-ci.yml file

I'm trying to use variables in my gitlab-ci.yml file. 我正在尝试在gitlab-ci.yml文件中使用变量。 This variable is passed as a parameter to a batch file that'll either only build or build and deploy based on parameter passed in. I've tried many different ways to pass my variable into the batch file but each time the variable is treated more like a static string instead. 该变量作为参数传递给批处理文件,该批处理文件将仅基于传入的参数进行构建或构建和部署。我尝试了多种方法将变量传递给批处理文件,但每次对变量进行更多处理时,像静态字符串一样。

I've read gitlabs docs on variables but cant seem to make it work. 我已经阅读了有关变量的gitlabs文档,但似乎无法使其工作。

  - build  

variables:
  BUILD_PUBLISH_CONFIG_FALSE: 0
  BUILD_PUBLISH_CONFIG_TRUE: 1

# BUILD ===============================
build: &build
    stage: build  
    tags: 
      - webdev  
    script:       
      - ./build.bat %BUILD_CONFIG%

build:branch:
  <<: *build
  variables:
    BUILD_CONFIG: $BUILD_PUBLISH_CONFIG_FALSE
  only:
    - /^(feature|hotfix|release)\/.+$/

build:branch:
  <<: *build
  variables:
    BUILD_CONFIG: $BUILD_PUBLISH_CONFIG_TRUE
  only:
    - /^(stage)\/.+$/

build:branch:
  <<: *build
  variables:
    BUILD_CONFIG: $BUILD_PUBLISH_CONFIG_TRUE
  only:
    - /^(master)\/.+$/

When watching gitlab's ci script execute, I expect ./build.bat 0, or ./build.bat 1. Each time it prints out as ./build.bat %BUILD_CONFIG% 观看gitlab的ci脚本执行时,我希望./build.bat 0或./build.bat1。每次将其打印为./build.bat%BUILD_CONFIG%

When you place variables inside job, that mean that you want to create new variable (and thats not correct way to do it). 当您将变量放入作业中时,这意味着您要创建新变量(那不是正确的方法)。 You want to output content of variable setup on top? 您想在顶部输出变量设置的内容吗? Can u maybe add that to echo? 您能否将其添加到回显中? or something like that? 或类似的东西? I didn't get it what you are trying to achieve. 我没有得到您想要达到的目标。

https://docs.gitlab.com/ee/ci/variables/#gitlab-ciyml-defined-variables https://docs.gitlab.com/ee/ci/variables/#gitlab-ciyml-defined-variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM