Snippets

Snippet - a pair of alias and body. Intended for use in properties of "config files" where available to use tokens.

General usage: [snippet:ALIAS].

Extended usage with variables: [snippet:ALIAS(key1:val1|key2:val2|...|keyN:valN)].

Why this need?

Sometimes you need use long (multi lines) property values in config files, which is not easy to handle in the JSON format. Snippets help do it easier and more transparent.

Furthermore, you will be able to use your snippets for any project and if you need to change something there, you need to change it only in one place, you do not have to edit every project.

Use cases

Email template

Assuming you want to receive email messages when Codario found some update.

You can create the following snippet with alias workflow.event.new-updates-available:

Hello [user:name],

We've found new updates for your project.

The following packages are ready to update:
[task:packages|<br>] — [package:name][/task:packages]

[task:url]

After this you can use this snippet in your JSON-configs:

"new_updates_available": [
  {
    "sendmail": {
      "emails": "me@mail.com",
      "subject": "New updates available",
      "message": "[snippet:workflow.event.new-updates-available]",
      "cc": "",
      "bcc": ""
    }
  }
]

SSH Template

Assuming you want to execute the commands via SSH connection that "pull updates" from your repository for every "test passed" event. And you have N projects on your server, every project in a separate folder.

In general case, your script has a look:

cd FOLDER_WITH_PROJECT
# set maintenance mode
git pull
composer install
# any other commands...
# clear cache
# set active mode

But how can you specify a different folder for every project? Actually - EASY. Just use "variables" inside your snippet:

You need create the following snippet with alias workflow.event.test-passed.ssh.get-updates:

cd /var/www/@folder
# set maintenance mode
git pull
composer install
# any other commands...
# clear cache
# set active mode

After this you can use this snippet in your JSON-configs:

"test_passed": [
  {
    "cicd": {
      "command": "[snippet:workflow.event.test-passed.ssh.get-updates(folder:personal-project)]",
      "alias": "ssh-default"
    }
  }
]

For this configuration, @folder will be changed to personal-project.

You can use as many variables as you need for every snippet.