Jenkins CI integrate with NodeJS and Github proble

2019-07-17 19:05发布

问题:

We have build our first Nodejs app and I want to integrate Jenkins as continuous integration we are running node server behind Nginx as proxy and source control in Gitlab. I need example configurations or steps. I am looking here any doc or wiki link or if you can point me into right direction it will be helpful I have CentOS server and managed to install and configure Jenkins but not getting the proper way to connect my Gitlab server. I need to run npm commands after each build. If any one already has done that please let me know.

Thanks

回答1:

Your question is still vague but I will try to provide you here how I had done Jenkins NodeJs with Gitlab integration. I have CentOS 6 and tested.

Steps

Open Java should be installed prior.

  • sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo

  • sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

  • sudo yum install jenkins
  • sudo service jenkins start

Login as jenkins

  • sudo -s -H -u jenkins

Now generate the ssh key in the folder /var/lib/jenkins/.ssh and copy that key to gitlab

  • ssh-keygen

  • Install Gitlab Hook Plugin and GitLab Plugin in jenkins.

As you will create a project by accessing your jenkins in browser After creating the project go to configure (left side menu) project page There lots of options are self explanatory - setup Git repo url and setup mail git browser url.

  • Create a new item in jenkins and add the git repo url and in build triggers select Build when a change is pushed to GitLab. GitLab CI Service URL:

Build Triggers
check the option

  • Build when a change is pushed to GitLab

  • Paste that url in your gitlab repo's webhooks in settings.

This is to run npm commands after build

There is one section SSH Publisher

In exec commands section (I have put my example you can write your commands)

    cd project_dir
    rm -rf public server package.json
    tar -xvf projectname.tgz 
    ls
    npm install --production
    export NODE_ENV=production 
    forever restartall
    jasmine-node spec/api/frisbyapi_spec.js 
    rm -rf projectname.tgz 

I have written most the steps that I took to setup jenkins nodejs and gitlab. I might have forgot any step. If you face any error please post that as well.