angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.68k stars 11.98k forks source link

Jenkins Integration #6377

Closed skofgar closed 7 years ago

skofgar commented 7 years ago

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x] question

Versions.

@angular/cli: 1.0.4
node: 7.9.0
os: darwin x64
@angular/animations: 4.1.3
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/material: 2.0.0-beta.5
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.0.4
@angular/compiler-cli: 4.1.3

Repro steps.

Created a project with angular CLI. Created a project on Jenkins using following shell execution steps:

npm install --silent
./ng test --code-coverage --single-run 
# I created a symlink for ng to the version installed by npm, see below

The log given by the failure.

n/a

Desired functionality.

I would like to integrate a project using Angular CLI onto our Jenkins server.

Mention any other details that might be useful.

I don't have a lot of Jenkins configuration experience, but from how it looks like it is not that simple out of the box. We are running compass on our Jenkins server, we have NPM version 4.6.1 on our Jenkins server. However, it looks like I need to adjust the configuration quite a bit more. Like changing Chrome to PhantomJS, convert the istanbul reports to cobertura reports etc. I even created a symlink for angular cli in the project, so we don't have to install it globally on the server using: ln -s node_modules/@angular/cli/bin/ng ng.

I feel like I am missing something obvious and all these steps shouldn't be necessary. Unfortunately I am not finding any documentation about CI integration here or somewhere else (google...).

Could you give me some pointers/hints please?

skofgar commented 7 years ago

E.g. Is there a karma.conf template for jenkins?

skofgar commented 7 years ago

Thinking about it, my question is probably not that clear and might be more Angular 4 related than Angular CLI... It seems like PhantomJS is currently not supporting ES6, but maybe I misread that. I will look into this more tomorrow.

PikaChokeMe commented 7 years ago

I have a Jenkins CI job setup that runs and builds angular...

As a part of the Jenkins job we do not install the CLI globally on our build machines at all, but instead call npm install on each git pull down that kicks off the job. This will install whatever version of the CLI that the package.json specifies for that particular revision.

We also do testing with ng test --single-run --code-coverage (which typically works fine) and we've never had any issues testing on chrome.

I hope that this is helpful but if you need anything more specific I'd be happy to help you out.

skofgar commented 7 years ago

@BustyLoli-Chan thanks a lot for your answer. That's very helpful. For some reason I thought I'd need a headless browser, but I am having issues getting it working with PhantomJS. Also, I was hoping I could put the browser onto the package.json – as a dependency – , however as far as I know this is only possible with PhantomJS. But I will give it a try with Chrome and report back.

One question: Did you also use a symlink or ./node_modules/@angular/cli/bin/ng – since you didn't install Angular CLI globally?

PikaChokeMe commented 7 years ago

Package.json "karma-chrome-launcher": "~2.1.1",

It wasn't necessary to make a symlink since running an npm install just downloads and puts the "binaries" in the local directory.

skofgar commented 7 years ago

@BustyLoli-Chan Thanks!

Hmm.. that's odd.. in our installation it wasn't able to find/use 'ng' in the project folder, even after running npm install. I will investigate that. Thanks for pointing that out.

PikaChokeMe commented 7 years ago

we are windows machines. I don't know if ./ng would fair better for you since most linux machines don't have their current directory added to their path.

Most of our ng jobs are simply executed as bat 'npm run something' and in our package.json we would define

"scripts": {
    "something": "ng do something or other",
  },

I realize this actually different from what I first told you because technically it's running npm which is installed globally and npm is doing the intermittent lookup work to find the CLI and run its stuff

skofgar commented 7 years ago

@BustyLoli-Chan Oh okay! That makes sense though. Thanks for the explanation! I think I figured it out. I will close this issue now and add another comment explaining what I did as soon as I verified that everything works the way I want it.

skofgar commented 7 years ago

Thanks again for your help. So there were several things that confused me:

What I ended up doing was:

This is how our karma.conf.js ended up looking like:

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

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-phantomjs-launcher'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma'),
      require('karma-junit-reporter')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    junitReporter: {
            outputDir: "test-results",
            outputFile: "unit-test-results.xml"
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly', 'cobertura', 'text-summary' ],
      'report-config': {
        cobertura: {
          file: 'cobertura.xml'
        }
      },
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'junit', 'coverage-istanbul']
              : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false
  });
};

Thanks again for all your help 👍

cbeldacap commented 7 years ago

Hi all, I just set everything up to use PhantomJS in my Angular4 project. I've uncommented all the polyfills, added intl as a dependency, configured my karma.conf.json as @skofgar commented before and targeted to es5 on tsconfig.spec.json. I'm having this problem on and on though: image

Does anyone know how would be happening? Thanks a lot in advance,

Cristóbal

eliasre commented 7 years ago

@cbeldacap: As stated above phantomjs doesn't support es6, so it will choke on any 'const' variables in your test-code. Your non-test files should be transpiled before the tests start so you just need to avoid const in your testfiles and you should be good (use var instead)

cbeldacap commented 7 years ago

I could finally solve it importing some polyfills! (and some others not) :) in my case I ended up having those ones:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
// import 'core-js/es6/function';    
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
// import 'core-js/es6/date';
import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/set';

Already solved and totally working!

akshayjai1 commented 6 years ago

can anyone help here https://stackoverflow.com/questions/47315228/deploying-an-angular-application-using-continuous-integration-from-git-or-gitlab

angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.