Continuous integration GitLab CI:在脚本生成作业之前导出变量

Continuous integration GitLab CI:在脚本生成作业之前导出变量,continuous-integration,gitlab,gitlab-ci,gitlab-ci-runner,Continuous Integration,Gitlab,Gitlab Ci,Gitlab Ci Runner,我尝试根据CI脚本是否为标记的分支运行来实现条件版本控制。 但是,未解析版本变量。相反,它被打印为字符串 GitLab CI脚本的相关作业: # build template .build_base_template: &build_base_template image: registry.gitlab.com/xxxxxxx/npm:latest tags: - docker stage: LintBuildTest script: - export

我尝试根据CI脚本是否为标记的分支运行来实现条件版本控制。 但是,未解析版本变量。相反,它被打印为字符串

GitLab CI脚本的相关作业:

# build template
.build_base_template: &build_base_template
  image: registry.gitlab.com/xxxxxxx/npm:latest
  tags:
    - docker
  stage: LintBuildTest
  script:
    - export CUR_VERSION='$(cat ./version.txt)$BUILD_VERSION_SUFFIX'
    - npm ci
    - npm run build
  artifacts:
    expire_in: 1 week
    paths:
      - dist/

# default build job
build:
  before_script:
    - export BUILD_VERSION_SUFFIX='-$CI_COMMIT_REF_SLUG-SNAPSHOT-$CI_COMMIT_SHORT_SHA'
  <<: *build_base_template
  except:
    refs:
      - tags
  only:
    variables:
      - $FEATURE_NAME == null

# specific build job for tagged versions
build_tag:
  before_script:
    - export BUILD_VERSION_SUFFIX=''
  <<: *build_base_template
  only:
    refs:
      - tags
#构建模板
.build\u base\u模板:&build\u base\u模板
图片:registry.gitlab.com/xxxxxxx/npm:latest
标签:
-码头工人
阶段:测试
脚本:
-导出当前版本=“$(cat./VERSION.txt)$BUILD\u VERSION\u后缀”
-npm ci
-npm运行构建
人工产品:
过期时间:1周
路径:
-距离/
#默认生成作业
建造:
在脚本之前:
-导出生成版本后缀='-$CI\u COMMIT\u REF\u SLUG-SNAPSHOT-$CI\u COMMIT\u SHORT\u SHA'

通常,您不能将变量从子进程导出到父进程


作为解决方法,您可以使用文本文件来写入/读取变量值。也可以通过yaml模板传递变量。

通常,您不能将变量从子进程导出到父进程


作为解决方法,您可以使用文本文件来写入/读取变量值。也可以通过yaml模板传递变量。

脚本之前导出的变量在脚本中可见

before:
  before_script:
    - export HELLOWELT="hi martin"
  script:
    - echo $HELLOWELT  # prints "hi martin"

在脚本之前导出的变量在脚本中可见

before:
  before_script:
    - export HELLOWELT="hi martin"
  script:
    - echo $HELLOWELT  # prints "hi martin"

我的同事能够解决这个问题。我想为大家提供解决方案:首先需要调用build\u base\u模板(在
行上方),然后我的同事才能解决问题。我想为大家提供解决方案:首先需要调用build\u base\u模板(在脚本之前的
行上方