0

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}],
   }
dome
  • 820
  • 7
  • 20
doesnotmatter
  • 21
  • 1
  • 6

1 Answers1

0

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

renefritze
  • 2,167
  • 14
  • 25
  • good thing, I got to try it both the ways in the past few months. I did overwrite the packages.json using sed for it to take the branch name. And in another circumstance, I had to parse this JSON to install a dependency, a python script only to parse the JSON helped. Thank you for your answer! – doesnotmatter Jan 23 '20 at 07:06