gitlab-ci:从文件预加载变量

问题描述 投票:0回答:1

我有一个像这样的简单舞台:

build-hw:
  stage: build
  when: on_success
  timeout: 10 hours
  before_script:
    source /usr/local/bin/setup_env.sh
  script:
    - make build
    - make export_hw sw/$SW_PRJ/xsa
  artifacts:
    name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA"
    expire_in: 1 hour
    paths:
      - $HW_PRJ/$HW_PRJ.runs/*.log
      - $HW_PRJ/$HW_PRJ.runs/impl_1/top.bit
      - $HW_PRJ/$HW_PRJ.runs/impl_1/top.ltx
      - sw/$SW_PRJ/xsa/top.xsa

以及 .gitlab-ci 文件中设置的一些变量

variables:
      HW_PRJ: "pl-build"
      SW_PRJ: "ps-build"

我已经做了什么:

  1. 创建“.env”并将这些变量放在那里
  2. 用另一行编辑before_script:set -o allexport;源.env;设置+o allexport`

但它仅在 script 块内应用变量,而不是在 paths

有什么解决办法吗? 预先感谢!

bash yaml gitlab-ci dotenv
1个回答
0
投票

GitLab 对此有一套机制,您不必做太多事情。您只需将变量写入文件并将其声明为具有

dotenv
结尾的工件,然后(取决于您如何设置它)可能会列出依赖项。

$: cat .gitlab-ci.yml
stages:
  - build

save-env:
  stage: ".pre"
  script: |
    when=$(date +%s)
    printf "%s\n" "thing1='foo'" "thing2='$when'" > sav.env
  tags:
    - VM
  artifacts:
    reports:
      dotenv: sav.env

show-vars:
  stage: build
  script: echo "got [$thing1], [$thing2]"
  tags:
    - VM
  dependencies:
    - save-env

show-vars
日志的最后几行:

Executing "step_script" stage of the job script
$ echo "got [$thing1], [$thing2]"
got ['foo'], ['1711048904']
Cleaning up project directory and file based variables
Job succeeded
© www.soinside.com 2019 - 2024. All rights reserved.