如何在Jenkins env变量中为Headless Chrome配置CHROME_BIN路径

时间:2019-04-02 07:33:58

标签: angular jenkins jenkins-pipeline google-chrome-headless

我正在从事基本的Angular项目,并且能够在Windows上使用无头镀铬对karma和Jasmin进行测试。但是詹金斯说No binary for ChromeHeadless browser on your platform,所以问题是如何在詹金斯配置中配置ChromeHeadless。

错误日志

  

您的平台上没有适用于ChromeHeadless浏览器的二进制文件。请设定   CHROME_BIN“环境变量。npmERR!测试失败。

package.json

 "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~6.0.8",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "^2.9.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage": "^1.1.2",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-sonarqube-unit-reporter": "0.0.18",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "^2.9.2"
  }

karma.conf.js

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {

  config.set({
    basePath: '',
    // captureTimeout: 60000, // it was already there
    // browserDisconnectTimeout: 10000,
    // browserDisconnectTolerance: 1,
    // browserNoActivityTimeout: 60000, //by default 10000
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-coverage'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      // require('@angular/cli/plugins/karma'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-sonarqube-unit-reporter'),
      // require('karma-phantomjs-launcher')

    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      // dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      useBrowserName: false,
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml', 'sonarqubeUnit', 'coverage'],
    sonarQubeUnitReporter: {
      outputFile: '../../target/angular_reports/ut_report.xml',
      useBrowserName: false
    },
    // angularCli: {
    //   environment: 'dev'
    // },
    coverageReporter: {
      // specify a common output directory
      dir: '../../target/angular_reports/coverage',
      reporters: [
        // reporters not supporting the `file` property
        {
          type: 'html',
          subdir: 'report-html'
        },
        {
          type: 'lcov',
          subdir: 'report-lcov'
        },
        // reporters supporting the `file` property, use `subdir` to directly
        // output them in the `dir` directory
        {
          type: 'cobertura',
          subdir: '.',
          file: 'cobertura.txt'
        },
        {
          type: 'lcovonly',
          subdir: '.',
          file: 'report-lcovonly.txt'
        },
        {
          type: 'teamcity',
          subdir: '.',
          file: 'teamcity.txt'
        },
        {
          type: 'text',
          subdir: '.',
          file: 'text.txt'
        },
        {
          type: 'text-summary',
          subdir: '.',
          file: 'text-summary.txt'
        },
      ]
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    // browsers: ['Chrome'],
    // browsers: ['ChromeHeadless'],
    // browsers: ['Chrome'],
    browsers: ['MyHeadlessChrome'],
    // browsers: ['Chrome', 'ChromeHeadless', 'MyHeadlessChrome'],
    customLaunchers: {
      MyHeadlessChrome: {
        base: 'ChromeHeadless',
        flags: ['--disable-translate', '--disable-extensions', '--remote-debugging-port=9223']
      }
    },
    // singleRun: false
    singleRun: true
  });
};

1 个答案:

答案 0 :(得分:-1)

您可以将CHROME_BIN环境变量设置为chrome浏览器可执行文件的位置