我正在使用grunt-msdeploy将angularJs代码部署到服务器之一,这非常合适。我想将相同的代码部署到多个服务器。我如何实现它?请帮忙!
msdeploy的Gruntfile.js代码:
var path = require('path');
//add the config file name
var configFile = path.resolve('./deployconfig.json');
var config = require(configFile);
msdeploy: {
push: {
options: {
verb: 'sync',
allowUntrusted: 'true',
source: {
'contentPath': path.resolve('./dist')
},
dest: {
contentPath: config.contentPath,
wmsvc: config.serverAddress,
userName: config.userName,
password: config.password
}
}
}
}
grunt.loadNpmTasks('grunt-msdeploy');
//add task for deployment - copying the dist from local server to remote server
grunt.registerTask('deploy', ['msdeploy:push']);
deployconfig.json:
{
"contentPath": "c:/inetpub/wwwroot/dist",
"serverAddress": "ec2-xx-xx-xx-x.ap-northeast-1.compute.amazonaws.com",
"userName": "xxxxxxxxx",
"password": "xxxxxxxxx"
}
我已尝试在msdeploy中使用多个dest,并在json文件中使用多个服务器信息,但这并不起作用。有没有办法做到这一点?
答案 0 :(得分:4)
我认为你正在配置错误的任务,这就是为什么它在你的情况下不起作用,它应该定义为grunt的tak,这里是伪代码:
grunt.initConfig({
msdeploy: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
更多信息和选项in the official manual。
对于多个目的地,只需创建多个target
说明,
grunt.initConfig({
msdeploy: {
options: {
// Task-specific options go here.
},
your_target_1: {
// Target-specific file lists and/or options go here.
},
your_target_2: {
// Target-specific file lists and/or options go here.
},
...
},
});
您可以为所有options
创建targets
通用名称,并为每个options
创建特定target
。
当您运行任务时,只需不指定您需要运行的目标,它将逐个执行:
// will be executed for all the targets from task `msdeploy` definition
grunt.registerTask('deploy', ['msdeploy']);
// or alternatively you may explicitly define the order of tasks:
grunt.registerTask('deploy', ['msdeploy:your_target_1', 'msdeploy:your_target_2']);
答案 1 :(得分:0)
这是可行的解决方案:
18:25:25: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:Android:artifactoryPublish
Deploying build descriptor to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375127269
BUILD SUCCESSFUL
如果有人想要使用配置文件执行此操作,请向json配置文件添加多个条目,如下所示:
msdeploy: {
target1: {
options: {
verb: 'sync',
allowUntrusted: 'true',
source: {
'contentPath': path.resolve('./dist')
},
dest: {
contentPath: "target1path",
wmsvc: "target1serverAddress",
userName:"target1userName",
password:"target1password"
}
}
},
target2: {
options: {
verb: 'sync',
allowUntrusted: 'true',
source: {
'contentPath': path.resolve('./dist')
},
dest: {
contentPath: "target2path",
wmsvc: "target2serverAddress",
userName:"target2userName",
password:"target2password"
}
}
}
}
grunt.registerTask('deploy', ['msdeploy:target1', 'msdeploy:target2']);
,值可以称为:
[
{
"contentPath": "c:/inetpub/wwwroot/dist",
"serverAddress": "ec2-xx-xxx-xx-xxx.ap-northeast-1.compute.amazonaws.com",
"userName": "xxxxxxxxxx",
"password": "xxxxxxxxx"
},
{
"contentPath": "c:/inetpub/wwwroot/dist",
"serverAddress": "ec2-xx-xxx-xx-xxx.ap-northeast-1.compute.amazonaws.com",
"userName": "xxxxxxxxxx",
"password": "xxxxxxxxx"
}
]