i have a project in grunt and can scp to different servers and copy stuff with grunt scp
but every time when i have to scp to either test or production i have to change the host name in gruntfile.js
and then commit it back to svn
in order to run it via jenkins.So what i want is to create some environment varible on the basis of which my i can add some parameters in jenkins and when i select any of the parameter e.g. test
by build will get deploy to test and so on. my scp code is below
scp: {
options: {
host: 'testserver',
username: 'user',
privateKey: fs.readFileSync('/repository/server/.ssh/id_rsa_robot'),
tryKeyboard: true
},
dist: {
files: [{
cwd: './dist',
src: '**/*',
filter: 'isFile',
// path on the server
dest: '/path/to/deploy/project.test'
}]
}
}
i want to use something like
grunt deploy:test
or
grunt deploy:production
and ask jenkins
to do that scp
please help !!
Never used Grunt, but any parameter that you configure in Jenkins under "This build is parameterized" section is available as environment variables for the processes under that build (with the same name as configured)
According to this answer, Read environment variables in Node.js, to read an environment variable in nodejs (and I understand that Grunt uses nodejs), all you need is:
process.env.ENV_VARIABLE
Where ENV_VARIABLE
is the name of the environment variable, as configured in Jenkins.
So, in your case:
Hostname
host: process.env.Hostname,