Search code examples
configurationenvironment-variablessemantic-release

How can I use environmental variables in the .releaserc.json?


I want to do something like this,

["@semantic-release/exec", {
  "prepareCmd": "echo hello ${HOME};"
}],

And then run this CI job with an environmental variable? Is there a method of making this work in semantic-release?


Solution

  • Use .releaserc.js, or release.config.js

    You can rename the releaserc.json to release.config.js or .releaserc.js`, and then it's just a CommonJS module,

    const greets = "HELLO ";
    
    module.exports = {
        "foo": `${greets} ${process.title}`
    }
    

    That will run as expected.

    Internally semantic-release uses cosmiconfig