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) {
console.log(custom_argument_that_i_can_pass_via_teamcity);
deployer
.deploy(test);
};
Best Answer
The official truffle documentation addresses your issue:
There you add your different environment configurations.
Below in the doc, it says how to send the env to use to truffle:
Update:
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 yourcustom_param
from it:And then executing
truffle migrate --custom_argument "hello beautiful world"
prints
----migration custom argument: hello beautiful world
.Hope this helps.