Stages
In a step, the index.js
file implements the flow. The scaffold generates a file like this:
'use strict';
module.exports = {
check: function() {
this.logger.info('#blue', 'Check if all you need to execute this step exists');
},
config: function() {
this.logger.info('#yellow', 'Config the step to run');
},
run: function(ok, ko) {
this.sh('echo Run main execution of the step', ko, true);
},
prove: function() {
this.logger.info('#green', 'Check if the step has run ok');
},
notify: function() {
this.logger.info('#grey', 'Notify the end of the shot to someone or something');
},
emit: function() {
this.logger.info('#white', 'Emit the result of the step to other steps. Allow communication between steps');
return { message: 'emit a message' };
}
};
And the stages of a step by default are:
check
: check if all you need to execute this step exists.config
: config the step to run.run
: run main execution of the step.prove
: check if the step has run ok.notify
: notify the end of the step to someone or something.emit
: emit the result of the step to other steps. Allow communication between steps.
Promises
Note that all the stages are promises functions, they has two optional paramenter 'resolve', 'reject';
A example with resolve
and reject
:
module.exports = {
run: function(resolve, reject) {
if (this.params.jsonIsWellFormed) {
resolve();
} else {
reject();
}
return;
}
};
check
stage
Check if all you need to execute this step exists. Here you can see some examples:
- System requirement. But check first requirements configuration options.
- Maybe check if some inputs are all well formed. For example a json well formed.
- Or check if the environment has a global variable setted.
- ...
config
stage
Config the step to run. Do you need to config something, this is the stage to do it.
run
stage
Run main execution of the step. This stage hope that all that it need to implement a process is 'ok', because it has been provide by the above stage.
prove
stage
Check if the step has run ok.
- If artifacts has been well built.
- or if there is a inexpected file created.
notify
stage
Notify the end of the shot to someone or something.
- Email to an address.
- Notify to a slack channel.
- ...
emit
stage
Emit the result of the step to other steps. Allow communication between steps.
See parameters between steps for more information.
Note:
Stages are configured on piscosour.json file of every recipe, it is possible to overwrite stages parameters on piscosour.json, see recipe configuration for more information.