简体   繁体   中英

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

The Problem is, that the mvn_settings file is resolved as text and not as path. 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. 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. This is a bug in GitLab, and something that they might fix in an upcoming release. Here is the issue on GitLab for it:

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. 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.

Assuming you name the file variable as ENV_FILE_DEV in the CI/CD setting, you can do this as a workaround:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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