1

当我尝试使用模板变量时,例如{{hostname}}作为值的一部分,它会被双引号括起来。

如何添加不带引号的变量?

例子:

---
resource_types:
  - name: maven
    type: docker-image
    source:
      repository: patrickcrocker/maven-resource
      tag: latest

resources:
  - name: maven-snapshot
    type: maven
    source:
      url: http://{{hostname}}:8081/repository/maven-snapshots/

  - name: repo
    type: git
    source:
      uri: "git@bitbucket.org:foo/bar.git"
      branch: master{{hostname}}

该命令的结果fly -t ci set-pipeline --pipeline test --config test.yml --var="hostname=localhost"如下(查看"localhost"):

resources:
  resource maven-snapshot has been added:
    name: maven-snapshot
    type: maven
    source:
      url: http://"localhost":8081/repository/maven-snapshots/

  resource repo has been added:
    name: repo
    type: git
    source:
      branch: master"localhost"
      uri: git@bitbucket.org:foo/bar.git

resource types:
  resource type maven has been added:
    name: maven
    type: docker-image
    source:
      repository: patrickcrocker/maven-resource
      tag: latest

我包含 3rd-party maven 资源的原因是 git 资源不允许{{}}在 中uri,导致错误:

failed to unmarshal configStructure: yaml: line 17: did not find expected key
4

2 回答 2

2

更新

concourse v3.2.0 开始 {{someValue}},不推荐使用语法,取而代之的是((someValue)). 新语法将理解您正在尝试插入字符串并相应地放置值。

替换{{hostname}}((hostname))将解决您的问题:

resources:
  - name: maven-snapshot
    type: maven
    source:
      url: http://((hostname)):8081/repository/maven-snapshots/

大堂不支持这一点。Concourse yaml 模板非常原始,不能在字符串中间插入变量。您将需要将您的url参数设置为http://localhost:8081/repository/maven-snapshots/,并将您的分支参数设置为localmaster或任何应有的值。

我们知道这是一个问题,我们正在努力解决这个问题,但现在您无法以您想要的方式设置变量。

于 2017-04-02T06:19:07.337 回答
1

在等待 concourse 团队提供此功能时,我编写了这个小型可执行文件来解决此 GitHub 存储库中的问题:

https://github.com/sercant/inline-yaml

我像这样准备我的 config.yml:

ftp-username: username
ftp-password: password
ftp-uri: 192.168.1.2
ftp-dir: home/ftp/

ftp-uri-combined: ftp://{{ftp-username}}:{{ftp-password}}@{{ftp-uri}}/{{ftp-dir}}

ftp-uri-combined-html5: {{ftp-uri-combined}}html5
ftp-uri-combined-android: {{ftp-uri-combined}}android

并准备了一个create-pipeline.sh:

#!/usr/bin/env sh
TEMP=$(mktemp)

java -jar inline-yaml.jar $3 ${TEMP};
fly -t lite set-pipeline -p $2 -c $1 --load-vars-from ${TEMP};

rm ${TEMP};

每当我需要创建管道时,我都会运行:

./create-pipeline.sh build-plan.yml build-plan-name config.yml
于 2017-05-16T14:02:15.743 回答