Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

target_each

Marcel Kloubert edited this page Jan 6, 2018 · 5 revisions

Home >> Targets >> each

Each / loop

Iterates over a list of values and deploys for each of them.

The following example iterates over the 10 values of My SFTP server (s. from).

The target writes its values to the dir property (s. to) of Template for My SFTP server and starts a deployment for each of them.

{
    "deploy.reloaded": {
        "targets": [
            {
                "name": "My SFTP server",
                "type": "each",

                "description": "Deploys to 'Template for My SFTP server' for each of its values.",

                "from": [
                    "/home/myApp/dev_envs/dev1",
                    "/home/myApp/dev_envs/dev2",
                    "/home/myApp/dev_envs/dev3",
                    "/home/myApp/dev_envs/dev4",
                    "/home/myApp/dev_envs/dev5",
                    "/home/myApp/dev_envs/dev6",
                    "/home/myApp/dev_envs/dev7",
                    "/home/myApp/dev_envs/dev8",
                    "/home/myApp/dev_envs/dev9",
                    "/home/myApp/dev_envs/dev10"
                ],

                "to": [ "dir" ],

                "targets": [ "Template for My SFTP server" ]
            },

            {
                "name": "Template for My SFTP server",
                "type": "sftp",
                
                "description": "All values of 'My SFTP server' will be written to the 'dir' property of this target.",
                
                "host": "sandbox_srv", "port": 22,
                "user": "mkloubert",
                "privateKey": "/users/admin/.ssh/id_rsa",

                "dir": "You do not need to set this, because it is done by 'My SFTP server'",

                "isHidden": true
            }
        ]
    }
}
Name Description
from* A list of (source) values or the path / URL to a JSON file that contains the values.
to One or more property names of the target's settings where to write the values to.
targets One or more target (name) to deploy.
usePlaceholders Use placeholders for the source values or not. Default: (false)

* supports placeholders

External sources

Instead of defining an array in from property, you can define a string with path or URL to an external JSON file with data to iterate over.

Relative and local paths will be mapped to your home directory (.vscode-deploy-reloaded sub folder) or the .vscode folder.

For more information, s. external sources.

{
    "deploy": {
        "targets": [
            {
                // ...

                "from": "https://user:password@example.com/my-project/deploy/values.json",

                // ...
            },

            // ...
        ]
    }
}

How it works

The following TypeScript code demonstrates how the target works in general:

// iterate over "real" targets
// as defined in 'targets'
targets.forEach(currentTarget => {
    // set values
    // as defined in 'from'
    from.forEach(value => {
        // clone 'currentTarget'
        // to 'clonedTarget'

        // fill properties of 'clonedTarget'
        // as defined in 'to'
        // with 'value'
        to.forEach(property => {
            clonedTarget[property] = value;
        });

        // deploy 'clonedTarget'
    });
});

let numberOfExecutions = targets.length *
                         from.length;
Clone this wiki locally