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 '[[email protected],' [email protected], [email protected]]'

[2020-04-18T01:07:05.300Z] ERROR running force:package:install: Unexpected arguments: [email protected],, [email protected],, [email protected]]

Here is how the Dependencies Map looks like:

        "dependencies": [
            {
                "package": "[email protected]"
            },
            {
                "package": "[email protected]"
            },
            {
                "package": "[email protected]"
            }
        ]

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!

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .