如何在Concourse CI中使用yaml模板变量作为值的一部分

时间:2017-04-01 15:31:28

标签: concourse

当我尝试使用模板变量时,例如{{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

我之所以包含第三方maven资源的原因是git资源不允许{{}} uri,导致错误:

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

2 个答案:

答案 0 :(得分: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或其应该是什么。

我们知道这是一个问题,我们正在研究它,但是现在你不能以你想要的方式设置变量。

答案 1 :(得分:1)

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

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

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

Plunkr

准备了一个create-pipeline.sh:

$(document).ready(function() {

    $('.info-content-box').hide();

    var openedId = '';

    $('.info-box .info-header').click(function(e) {
        var id = '#' + $(this).data('name');

        if (openedId === '') {
            if ($(window).width() < 992) {
                $(id).insertAfter($(this).parent());
                $(id).slideToggle(400, function() {
                    openedId = id;
                });
            } else {
                $(id).slideToggle(400, function() {
                    openedId = id;
                });
            }
        } else {

            if (openedId == id) {
                if ($(window).width() < 992) {
                    $(id).insertAfter($(this).parent());
                    $(openedId).slideToggle(400, null);
                } else {
                    $(openedId).slideToggle(400, null);
                }
            } else {
                $(openedId).hide(10);
                if ($(window).width() < 992) {
                    $(id).insertAfter($(this).parent());
                    $(id).fadeToggle(400, function() {
                        openedId = id;
                    });
                } else {
                    $(id).fadeToggle(400, function() {
                        openedId = id;
                    });
                }
            }
        }
    })
})

每当我需要创建一个管道时,我跑了:

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