在工件路径中使用脚本变量

Use script variable in artifact path

是否有在工件路径中使用 TEST_VAR 变量的任何更改?

inject:
  stage: inject
  script:
    - echo "testDownload.zip" > varName.txt
    - export TEST_VAR=$(cat varName.txt)
    - echo $TEST_VAR #This is working
    - wget http://some.url.com/download/testDownload.zip
  artifacts:
    name: 
    paths:
    - $TEST_VAR
    expire_in: 1h

在生产中,文件 testDownload.zip 将有一个变量名 (-.zip),我想以其原始名称将其提供给所有后续阶段。

谢谢

Andrew 是正确的(不幸的是)- 我在某个地方发现了以下“解决方法”(不是很好,也不是很糟糕):

variables:
  INJECTION_PATH: "./Test/"


inject:
  stage: inject
  before_script:
    - sudo apt-get -qq install unzip
  script:
    - wget hhttp://some.url.com/download/7d8e6751-2ca3-477c-9185-7097932c3043.zip
    - unzip ./7d8e6751-2ca3-477c-9185-7097932c3043.zip -d $INJECTION_PATH
  artifacts:
    paths:
      - $INJECTION_PATH
    expire_in: "600"

这将使 $INJECTION_PATH 文件夹及其内容在每个阶段都可用,与文件夹中的文件名无关。

很遗憾,这是不可能的,请参阅 https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#gitlab-runner-internal-variable-expansion-mechanism :

GitLab Runner internal variable expansion mechanism

  • Supported: project/group variables, .gitlab-ci.yml variables, config.toml variables, and variables from triggers, pipeline schedules, and manual pipelines.
  • Not supported: variables defined inside of scripts (e.g., export MY_VARIABLE="test").

导出的变量仅在“*脚本”部分可用,有一些关于 after_script 的限制,请参阅 https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#execution-shell-environment

我的理解是,*script 部分之外的所有内容都在作业启动时初始化,并且无法在运行时重新定义。在您的情况下,您可以设置预定义路径(即 downloaded_artifact.zip),然后 wget 应将下载的内容保存到该文件中。要保留文件名,您可以在 downloaded_artifact.txt 中回显文件名,并将其传递到下一阶段。这很 hacky,但不幸的是,你不能在任何其他文件(或一些共享数据库,这可能是一个更 hacky 的解决方案)的阶段之间传递上下文。

相关工单:https://gitlab.com/gitlab-org/gitlab/-/issues/16765