[英]Integrate JSHint into Jenkins without using the Checkstyle or JSLint reporter
Is it possible to integrate JSHint into Jenkins without using the Checkstyle or JSLint reporter? 是否可以在不使用Checkstyle或JSLint报告器的情况下将JSHint集成到Jenkins中?
The reason why I want to do this is because both reporters by default also show non-errors , which is not what I want (see also JSHint shows non-errors for checkstyle reporter ). 我之所以这样做是因为默认情况下两个记者都显示非错误 ,这不是我想要的(另请参阅JSHint显示checkstyle报告的非错误 )。
Is there a way to integrate JSHint directly? 有没有办法直接集成JSHint?
I had similar problem last week, but I use grunt to run jshint. 上周我遇到了类似的问题,但我使用grunt来运行jshint。 I simply override jshint options, here is example code:
我只是覆盖jshint选项,这里是示例代码:
jshint: {
options: {
jshintrc: '../config/.jshintrc',
},
src1: [
'file1.js',
'file2.js'
],
src2: [
'source/file3.js',
'source/file4.js'
],
jenkins: {
options: {
jshintrc: '../config/.jshintrc',
reporter: 'checkstyle',
reporterOutput: 'jshint.xml',
},
src: [ "<%= jshint.src1 %>", "<%= jshint.src2 %>" ]
},
}
So when you want run jslint on jenkins you simply run: 所以,当你想在jenkins上运行jslint时,你只需运行:
grunt jshint:jenkins
and output is generated to .xml file. 并输出生成.xml文件。 I hope this may help you.
我希望这可以帮到你。
I would like to point out that jsHint will now work with the Report Violations, but you must set the report type to jslint-xml
. 我想指出jsHint现在将使用Report Violations,但您必须将报告类型设置为
jslint-xml
。 Here is a sample for the Ant task: 以下是Ant任务的示例:
<jshint dir="${js.dir}">
options="${jshint.options}">
<include name="**/*.js"/>
<exclude name="**/*.min.js"/>
<report type="jslint-xml"/>
</jshint>
Use the violations plugin for Jenkins, and put the name of your _jsHint_ XML output in the space for
jslint`. 使用Jenkins的违规插件,并将
_jsHint_ XML output in the space for
的名称放在_jsHint_ XML output in the space for
。
And, it's actually documented in the README.md
too. 而且,它实际上也记录在
README.md
。 I missed it. 我错过了。
This is an alternate way of implementing @mateusz's excellent answer. 这是实现@ mateusz优秀答案的另一种方式。 Instead of creating an additional target that combines all files with the extra report options, override the report and output only when
--jenkins
is passed in. 而不是创建将所有文件与额外报表选项组合在一起的其他目标,只有在
--jenkins
时才覆盖报表和输出。
var JENKINS = grunt.option('jenkins');
...
jshint: {
options: {
jshintrc: '../config/.jshintrc',
reporter: JENKINS && 'checkstyle',
reporterOutput: JENKINS && 'jshint.xml'
},
src1: [
'file1.js',
'file2.js'
],
src2: [
'source/file3.js',
'source/file4.js'
]
}
Not only does it avoid repeating the files, but in some cases you cannot combine them all into a single task. 它不仅避免重复文件,而且在某些情况下,您无法将它们全部合并到一个任务中。 In our case, we use different
.jshintrc
files for sources vs. tests. 在我们的例子中,我们对源和测试使用不同的
.jshintrc
文件。 A side benefit to this method is that you can easily apply the option to other tasks without repeating it for each. 此方法的另一个好处是,您可以轻松地将该选项应用于其他任务,而无需为每个任务重复。
$ grunt jshint --jenkins
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.