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

7gyucuyw  于 2023-01-04  发布在  ElasticSearch
关注(0)|答案(2)|浏览(132)

我正在gitlab pipeline中运行elasticsearch 7.0.1,下面是配置代码片段:

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不允许在变量名中使用点。我尝试用双下划线转义,但是没有成功。有什么建议吗?

pobjuy32

pobjuy321#

带有点的变量名在sh和bash中确实是无效的。
官方文档提供了一个解决方案(从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
x6yk4ghg

x6yk4ghg2#

您可以使用“command”,并使用后缀传递它:“-E{variable}”示例如下。

services:
   - name: "docker.elastic.co/elasticsearch/elasticsearch:8.5.3"
     alias: "elasticsearch"
     command: [ "bin/elasticsearch",
       "-Expack.security.enabled=false",
       "-Ediscovery.type=single-node",
       "-Ehttp.cors.enabled=true",
       '-Expack.ml.enabled=false']

相关问题