elasticsearch 7x作为gitlab服务不允许变量名中的点

分享于2022年07月17日 elasticsearch gitlab gitlab-ci 问答
【问题标题】:elasticsearch 7x作为gitlab服务不允许变量名中的点(elasticsearch 7x as gitlab service doesn't allow dot in variable name)
【发布时间】:2022-01-14 05:12:15
【问题描述】:

我正在尝试在我的 gitlab 管道中运行 elasticsearch 7.0.1,这里是配置 sn-p:

test:
  stage: test
  services:
    - name: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
      alias: elastic
  variables:
    cluster.initial_master_nodes: elastic
    node.name: elastic

但是当我运行它时,我收到以下错误消息:

/bin/bash: line 82: export: `cluster.initial_master_nodes=elastic': not a valid identifier

似乎 Gitlab 使用 bash 导出变量,但 bash 不允许名称中包含点。我尝试用双下划线转义但没有用。有什么建议吗?


【解决方案1】:

带点的变量名在 sh 和 bash 中确实无效。

official documentation 有一个解决方案(从 7.15 版开始工作):

Change the setting name to uppercase
Prefix it with ES_SETTING_
Escape any underscores (_) by duplicating them
Convert all periods (.) to underscores (_)

尝试变量名(注意双下划线):

ES_SETTING_CLUSTER_INITIAL__MASTER__NODES: elastic
ES_SETTING_NODE_NAME: elastic

  • 您错过了用双下划线转义下划线(我在答案中对其进行了编辑)。谢谢。