jenkins - 如何解决 Jenkins 上的 Gruntfile.js“意外令牌”错误?
问题描述
我无法弄清楚为什么我可以在本地机器上运行 grunt dev build 作业,但它在 Jenkins 服务器上失败并出现以下错误:
Loading "Gruntfile.js" tasks SyntaxError: Unexpected token ...
请注意,这项工作过去在 Jenkins 上每 10 分钟运行一次,直到有一天它停止工作。我想知道其他地方是否有更新,现在破坏了构建。我可以在本地机器上运行同样的繁重工作这一事实告诉我,Jenkins 上的某些内容已经更新,现在只在 Jenkins 上破坏了构建。
Gruntfile.js 文件对我来说看起来不错:
var argv = require('yargs')
.usage('$0 <cmd> [args]')
.string('env')
.required('env')
.choices('env', ['development', 'staging'])
.help()
.argv;
module.exports = function(grunt) {
var path = require('path');
var fs = require('fs');
var child_process = require('child_process');
grunt.log.writeln('Using ' + argv.env);
// Load plugins
grunt.loadTasks('grunt/tasks');
// Display execution time of grunt tasks
require('time-grunt')(grunt);
var buildId;
// Load all grunt configs
require('load-grunt-config')(grunt, {
configPath: path.join(process.cwd(), 'grunt/config'),
postProcess: function(config) {
// Modify path to the configuration file, without altering core grunt scripts.
config.properties.configFile = 'build/config.' + argv.env + '.json';
// Figure out version number
// Get build sequence id
var sequence = fs.readFileSync('../.buildsequence', 'utf8').replace(/[^0-9a-zA-Z]/g, '');
var build = process.env.BUILD_NUMBER.replace(/[^0-9a-f]/g, '');
// Get short git hash.
var hash = child_process.execSync('git describe --always').toString().toLowerCase().replace(/[^0-9a-f]/g, '');
grunt.log.writeln('Git hash ' + hash);
buildId = sequence + '-' + build + '-' + hash;
}
});
grunt.log.writeln();
grunt.log.writeln('********************************************');
grunt.log.writeln(' -- Initializing...');
// Load and parse configuration file(s)
require('./grunt/lib/config/loader')(grunt);
// Map legacy config to current format
require('./grunt/lib/config/mapper')(grunt);
// Normalize config (default values, correct format)
require('./grunt/lib/config/normalizer')(grunt);
// Avoids DEPTH_ZERO_SELF_SIGNED_CERT error for self-signed certs where hostname/IP do not match
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var settings = grunt.config.get('settings');
settings.project.build = buildId;
grunt.config.set('settings', settings);
//Output
grunt.log.write(' -- Initialization '); grunt.log.ok();
grunt.log.writeln();
grunt.log.writeln(' -- Project: ' + grunt.config('settings').project.name);
grunt.log.writeln(' -- Build: ' + grunt.config('settings').project.build);
grunt.log.writeln(' -- Version: ' + grunt.config('properties').version.name);
grunt.log.writeln(' -- Target: ' + grunt.config('environment').webdav.server);
grunt.log.writeln();
};
解决方案
推荐阅读
- javascript - $.scrollTo(this.hash || 0, 1500); ? 数字的含义是什么?
- apache-spark - 在 Spark 中使用“dropDuplicates”函数后获取删除记录的最佳方法
- mocking - 没有将结果作为 PHPUnit 对象模拟的数组
- mysql - 如何从所有数据都匹配且仅匹配的链接表中获取数据?
- java - 无法在 Java 项目中导入 com.auth0.jwt
- ansible - 在 Ansible 中基于扩展运行不同的脚本
- sql - Microsoft Access 查询输入条件
- sql - 如何在 PGSQL 中使用多个条件更新多个表列
- python - 理解python中的split()函数
- sql - ORA-00909: 使用 NVL 时参数数量无效