drone-env-parser

A simple parser that converts drones PLUGIN_ environment variables to a simple js object

Usage no npm install needed!

<script type="module">
  import droneEnvParser from 'https://cdn.skypack.dev/drone-env-parser';
</script>

README

drone-env-parser Build Status

This simple package allows you to conveniently parse the environment variables generated by drone via the settings section into a plain js object

Usage:

The most basic usage of this package looks like this:

const settings = require('drone-env-parser').parseEnvs();
// Now you can access your settings simply by referencing them like this for example:
Webservice.auth(settings.username, settings.password);

Configuration:

This package provides very basic configuration options which can be provided to it like this:

const settings = require('drone-env-parser').parseEnvs({
    // settings go here
});

Defaults

You can provide default values that will be overwritten by the values parsed from the environment variables

let settings = rquire('drone-env-parser').parseEnvs({
  defaults: {
    // define defaults here
  }
});

Splitting on comma:

If in the .drone.yml a list is provided at the top level like this:

steps:
 - name: Something
   image: also/something
   settings:
     a_list:
      - element 1
      - element 2
      - element 3

It gets encoded by drone into comma separated values and the environment variable resulting from that would look like this:

PLUGIN_A_LIST=element 1,element 2,element 3

So if you enable splitOnComma (which is disabled by default) it will split every top level string at every comma. A side effect of this is, that every top level string will be an array.

If this behaviour is desired, you can enable it by setting splitOnComma: true.

Making names lowercase

By default this package will always turn top level property names into lowercase, as drone provides the environment variables as all uppercase.

If this behaviour is not desired, you can disable it by setting makeNameLowerCase: false

Custom prefix

By default this package will filter the environment variables out that don't start with PLUGIN_ and the parse the name beginning after the PLUGIN_.

If, for what ever reason this needs to be changed, you can modify the prefix this package will look for by setting prefix: 'CUSTOM_'.