0

I am trying to create a Jenkins pipeline to install package dependencies and my code looks like this:

def data = readJSON file:'sfdx-project.json'
for (item in data.packageDirectories.dependencies) {
    println "${item.package}"
    sh "${SFDX} force:package:install -p ${item.package}"
}

But whenever this runs in jenkins it fails with this error:

[2020-04-18T01:07:04.729Z] + node_modules/sfdx-cli/bin/run force:package:install -p '[PackageA@1.3.4-2,' PackageB@1.0.2-1, PackageC@1.0.0-1]'

[2020-04-18T01:07:05.300Z] ERROR running force:package:install: Unexpected arguments: PackageA@1.0.2-1,, PackageB@1.0.0-1,, PackageC@1.0.0-1]

Here is how the Dependencies Map looks like:

        "dependencies": [
            {
                "package": "PackageA@1.3.4-2"
            },
            {
                "package": "PackageB@1.0.2-1"
            },
            {
                "package": "Packagec@1.0.0-1"
            }
        ]

To me it looks like that for some reason it is not properly iterating over the items in data.packageDirectories.dependencies.

Any ideas/Recommendations on how to solve this would be awesome. Fairly new to groovy so if I am doing something noobish point it out!

0

After some further digging I came up with this:

def data = readJSON file:'sfdx-project.json'
def packages = data.packageDirectories.dependencies.flatten()                
packages.each { item -> 
println "$item.value"
   sh "${sfdx} force:package:install -p $item.value"
}

Taken from: http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#_iterating_on_maps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.