当尝试将用户私钥传递给grunt-ssh时,我希望每个开发人员能够在Gruntfile中加载的Gruntsetting.json中设置他们的服务器密钥,如下所示:
settings: grunt.file.readJSON('Gruntsettings.json'),
sshexec: {
test: {
command: 'uptime',
options: {
privateKey: grunt.file.read('<%- settings.keyPath %>'),
host: '<%= settings.host %>',
username: '<%= settings.username %>'
}
},
}
但是当我在grunt.file.read语句中使用keyPath设置时,我收到错误:
Error: Unable to read "<%- settings.keyPath %>" file (Error code: ENOENT).
是否可以将读取json文件中的变量传递回另一个读取命令?
答案 0 :(得分:4)
展开privateKey
模板以包含文件读取方法调用:
settings: grunt.file.readJSON('Gruntsettings.json'),
sshexec: {
test: {
command: 'uptime',
options: {
privateKey: '<%= grunt.file.read(settings.keyPath) %>',
host: '<%= settings.host %>',
username: '<%= settings.username %>'
}
},
}