1.0.6 • Published 6 years ago
serverless-git-version-plugin v1.0.6
serverless-git-version-plugin
This plugin works with serverless and serverless-offline. It generates files version.txt and branch.txt in the root folder of your project by parsing the output of
- git rev-parse HEAD
- git branch --list
Quickstart
- run npm install serverless-git-version-plugin
- update your serverless.yml to include reference to plugin
plugins:
- serverless-git-version-plugin
- update your serverless.yml to read version into evironment variable
environment:
version: ${file(./version.txt)}
branch: ${file(./branch.txt)}
- start your service sls offline or deploy it sls deploy
- now version your lambdas can read version from
process.env.version
Usage in the real world
See the example below:
module.exports.version = function(event, context, callback) {
let results={"code_version":"","git_branch":""};
if (process.env.version) {
results.code_version = process.env.version;
}
if (process.env.branch) {
results.git_branch = process.env.branch;
}
callback(null, {body: JSON.stringify(results)});
}