pass the arguments in a json file

2.5k Views Asked by At

I need to pass the branch name in git-dependencies as a parameter. But in my packages.json, I am unable to do so. The structure looks something like following:

{
    "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

There are 1 best solutions below

1
renefritze On

I suggest putting the mainstay of the final packages.json in a .template and simply appending the branch name and closing parens, etc at ci runtime. You can keep your 'true' package.json in git and just overwrite it then too.

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

If you have more involved needs for filling the packages.json I'd suggest using a python script with a string template or jinja template