在json文件中传递参数

时间:2019-06-11 09:09:24

标签: json gitlab gitlab-ci packages.json

我需要在git-dependencies中传递分支名称作为参数。但是在我的packages.json中,我无法这样做。该结构如下所示:

{
    "servers" : [
            ...
             ],
    "target" : "apps",
    "git" : {
            "git-remote" : "..."
        },
    "source" : {
            "git-dependencies-path": "../",
            "source-packages-path" : "../"
           },
    "wiki" : {
            "local-wiki-path" : "../",
            "git-wiki-path" : ""
         },
        "git-dependencies" : [  {"repository" : "application/app1", "branch" : "development", "source-packages" : [ "."]}, //the branch name I want to parameterize}],
   }

1 个答案:

答案 0 :(得分:0)

我建议将最后一个packages.json的主体放在.template中,并在ci运行时简单地附加分支名称和关闭括号等。 您可以将'true'package.json保留在git中,然后也将其覆盖。

package.json.template

{
    "servers" : [
            ...
             ],
    "target" : "apps",
    "git" : {
            "git-remote" : "..."
        },
    "source" : {
            "git-dependencies-path": "../",
            "source-packages-path" : "../"
           },
    "wiki" : {
            "local-wiki-path" : "../",
            "git-wiki-path" : ""
         },
        "git-dependencies" : [  {"repository" : "application/app1", "branch" : "development", "source-packages" : [ "

gitlab-ci.yml

- before_script: |
    cp packages.json.template packages.json
    echo "${CI_COMMIT_REF_NAME}" >> packages.json
    echo '"]},}' >> packages.json

如果您对填写packages.json有更多的需求,我建议使用带有string templatejinja template的python脚本