jenkinspipe道运行后unit testingkarma脚本不停止

我创build了unjenkinspipe道,运行一个docker容器和nodeJs,karma和xvfb来运行unit testing。 testing成功通过,但即使在karmaconfiguration中使用captureTimeout:60000和singleRun:true,脚本也不会停止

我错了

[33m05 04 2017 16:01:54.227:WARN [karma]: [39mNo captured browser, open http://localhost:9876/ [32m05 04 2017 16:01:54.260:INFO [karma]: [39mKarma v1.3.0 server started at http://localhost:9876/ [32m05 04 2017 16:01:54.262:INFO [launcher]: [39mLaunching browser Chrome with unlimited concurrency [32m05 04 2017 16:01:54.282:INFO [launcher]: [39mStarting browser Chrome [32m05 04 2017 16:01:59.120:INFO [Chrome 57.0.2987 (Linux 0.0.0)]: [39mConnected on socket /#0Rk4DaJRdDHKCHNvAAAA with id 66659056 Chrome 57.0.2987 (Linux 0.0.0): Executed 0 of 2 SUCCESS (0 secs / 0 secs) [1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 1 of 2 SUCCESS (0 secs / 0.99 secs) [1A[2KLOG: 'MAIN' Chrome 57.0.2987 (Linux 0.0.0): Executed 1 of 2 SUCCESS (0 secs / 0.99 secs) [1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 2 of 2 SUCCESS (0 secs / 1.269 secs) [1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 2 of 2 SUCCESS (1.319 secs / 1.269 secs) 

pipe道:

  def karma = docker.image('trion/ng-cli-karma') karma.pull() try { karma.run(' -u $(id -u) -v ${WORKSPACE}:/app trion/ng-cli-karma ') karma.inside { sh 'npm install' try { sh('ng test') }catch(err) { sh 'echo TEST FAILED' step([$class: 'JUnitResultArchiver', testResults: 'report/*.xml', healthScaleFactor: 1.0]) throw err } sh 'echo DO SOMETHING ELSE AFTER TEST' } sh 'ls -al ' } catch(err) { sh 'echo RUN DOCKER FAILED' throw err } 

Karma conf:

 module.exports = function (config) { config.set({ mime: { 'text/x-typescript': ['ts','tsx'] }, basePath: '', frameworks: ['jasmine', 'angular-cli'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-remap-istanbul'), require('angular-cli/plugins/karma'), require('karma-junit-reporter') ], files: [ { pattern: './src/test.ts', watched: false } ], preprocessors: { './src/test.ts': ['angular-cli'] }, remapIstanbulReporter: { reports: { html: 'coverage', lcovonly: './coverage/coverage.lcov' } }, angularCli: { config: './angular-cli.json', environment: 'dev' }, reporters: config.angularCli && config.angularCli.codeCoverage ? ['progress', 'karma-remap-istanbul'] : ['progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], customLaunchers: { Chrome_without_sandbox: { base: 'Chrome', flags: ['--no-sandbox'] // with sandbox it fails under Docker } }, junitReporter: { outputDir: './report', // results will be saved as $outputDir/$browserName.xml outputFile: 'report.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile suite: '', // suite will become the package name attribute in xml testsuite element useBrowserName: false, // add browser name to report and classes names nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element properties: {} // key value pair of properties to add to the <properties> section of the report }, reporters: config.angularCli && config.angularCli.codeCoverage ? ['progress', 'karma-remap-istanbul', 'junit'] : ['progress', 'junit'], captureTimeout: 60000, singleRun: true }); }; 

编辑:07/04/2017没有人可以帮助我,也可能是我不清楚,我的问题是当我运行我的jenkinspipe道“运行unit testing”一步从未完成(比较截图),我不能检查是否我的考试通过或不开展下一步。 我需要帮助,知道如何在业力testing完成后用命令行或其他方法来阻止它。

我尝试使用karmaconfiguration(captureTimeout:60000,singleRun:true),但没有发生任何事情

在这里输入图像说明

我认为业力正在关注对于开发机器而言不错的变化,但对CI构build不利。 如果你想避免改变业绩configuration,你可以传递--watch false作为参数ng test 。 (虽然你有singleRun: true我不确定autoWatch: true是否有更高的优先级。)

我build议你使用docker容器来执行完整的构build,而不是单一的docker运行命令。 Jenkins提供了一个很好的抽象来在Docker容器中运行命令:

 docker.image('trion/ng-cli-karma').inside { stage ('load npm dependencies') { echo 'Load npm dependencies' sh 'npm install' } stage ('build') { echo "building" sh 'npm run build' } stage ('unit test') { sh 'ng test --progress false --watch false' echo 'generate test report **/dist/test-reports/*.xml' junit allowEmptyResults: false, testResults: '**/test-results.xml' echo 'end test & coverage' } ... 

我解决了这个问题,之前在我的Jenkinsfile中,我使用sh('ng test')命令来运行testing,而不知道后台发生了什么事情。

所以我直接使用了karma命令

 sh ('./node_modules/karma/bin/karma start karma.conf.js')