简体   繁体   English

Gitlab Ci文件变量内容而不是路径

[英]Gitlab Ci File Variable content instead of path

I am trying to set-up an pipline for building and testing our projects.我正在尝试建立一个管道来构建和测试我们的项目。 A have set up to file Variables on group level to use inside the pipeline Variables for mvn settings and certificate A 已在组级别设置文件变量以在管道变量中使用 mvn 设置和证书

The Problem is, that the mvn_settings file is resolved as text and not as path.问题是,mvn_settings 文件被解析为文本而不是路径。 So my build fails.所以我的构建失败了。

$ mvn $MAVEN_CLI_OPTS compile
Unable to parse command line options: Unrecognized option: --><!--

If I "echo" $mvn_settings I get the path.如果我“回显” $mvn_settings我得到了路径。 Also when im hard coding the path the pipeline is working My pipline:此外,当我对路径进行硬编码时,管道正在工作我的管道:

variables:
  ...
  MAVEN_CLI_OPTS: "--batch-mode -s '$mvn_settings'"

...
before_script:
  -  keytool -importcert -file "$db_trust" -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -trustcacerts -noprompt

generate:
  stage: generate
  script:
    - mvn $MAVEN_CLI_OPTS compile
  artifacts:
    paths:
      - target/
    expire_in: 3 days

...

Is there any way to determine when the pipeline is using the content and when the path?有什么方法可以确定管道何时使用内容以及何时使用路径?

When you use a file variable in the variables section in a .gitlab-ci.yml file, the variable is expanded to contain the content instead of the file name.当您在 .gitlab-ci.yml 文件的变量部分中使用文件变量时,该变量将扩展为包含内容而不是文件名。 This is a bug in GitLab, and something that they might fix in an upcoming release.这是 GitLab 中的一个错误,他们可能会在即将发布的版本中修复。 Here is the issue on GitLab for it:这是 GitLab 上的问题:

https://gitlab.com/gitlab-org/gitlab/issues/29407 https://gitlab.com/gitlab-org/gitlab/issues/29407

They have marked it with P2 , which means that they will try to fix it in 60 days from tagging it.他们用P2标记了它,这意味着他们将在标记后的 60 天内尝试修复它。 They seem to have missed the deadline for this month though.不过,他们似乎错过了本月的最后期限。

In the mean time, you might have to just use the variable manually where needed.同时,您可能只需要在需要的地方手动使用该变量。 If you have a huge .gitlab-ci.yml file, you might be able to use yaml anchors or the extends keyword to reuse part of your script without having to depend on the variable expansion.如果您有一个巨大的 .gitlab-ci.yml 文件,您可能可以使用yaml 锚点extends 关键字来重用部分脚本,而不必依赖于变量扩展。

Assuming you name the file variable as ENV_FILE_DEV in the CI/CD setting, you can do this as a workaround:假设您在 CI/CD 设置中将文件变量命名为ENV_FILE_DEV ,您可以将其作为一种解决方法:

variables:
  ENV_FILE: $CI_PROJECT_DIR/../$CI_PROJECT_NAME.tmp/ENV_FILE_DEV

Then the ENV_FILE variable will be available as the full path.然后ENV_FILE变量将作为完整路径可用。

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

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