I am having 3 different environments:

  • dev
  • test
  • live

I have one contract deployed on three different addresses, that I want to use based on environment, since for every environment we will store different data into smart contract.

I am using teamcity for CI, but I am interested how to differentiate environment with Truffle migrations, so based on environment to pick different address from inside of migration?

Example: Assume I have migration file:

    const test = artifacts.require("./test")

    module.exports = function(deployer, custom_argument_that_i_can_pass_via_teamcity) {


The official truffle documentation addresses your issue:

Your configuration file is called truffle.js and is located at the root of your project directory. This file is a Javascript file and can execute any code necessary to create your configuration. It must export an object representing your project configuration like the example below.

module.exports = {
  networks: {
    development: {
      host: "",
      port: 8545,
      network_id: "*" // Match any network id

There you add your different environment configurations.

Below in the doc, it says how to send the env to use to truffle:

truffle migrate --network live


I think I understand your question better now that you've added more details to it.

You have access to the process.argv global variable inside migration files, so you can use minimist to parse it and extract your custom_param from it:

const argv = require('minimist')(process.argv.slice(2), {string: ['custom_argument']});

module.exports = function(deployer) {
  console.log("----migration custom argument: ",argv['custom_argument']);

And then executing truffle migrate --custom_argument "hello beautiful world"

prints ----migration custom argument: hello beautiful world.

Hope this helps.

  • I updated answer, that's not what I needed. – amels May 29 '18 at 15:10
  • I've updated my answer also :) – Tudor Constantin May 29 '18 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.