Front-end CI/CD

1.Environments

  • AWS EC2 Linux && nginx
  • Java
  • Gitlab/Github

2.Install Jenkins

  • 1.switch root user
1
sudo -s
  • 2.update local yum repo
1
yum update
  • 3.get jenkins remote repo package
1
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
  • 4.get jenkins repo key
1
rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
  • 5.install jenkins
1
yum install jenkins --nogpgcheck
  • 6.set to run on startup
1
2
service jenkins start
chkconfig jenkins on

3.Jenkins plugins install

  • 1.Install NodeJS plugin
  • 2.Enter the Global Tool Configuration => new NodeJS
  • 3.Install Publish Over SSH(Send build artifacts over SSH)
  • 4.Install Generic Webhook Trigger(Dynamically associate the Git repository)
  • 5.Install Email Extension Plugin(Ignore it if it exists)

4.Build Github Project

  • 1.Create Freestyle project
  • 2.Select Github Project => Project URL input your repo url => Source code management select git && input git address => build Enviroment select provide Node & npm bin/folder to PATH => Select your NodeJs version => build select excu shell => input shell script
1
2
3
node -v &&
npm install &&
npm build
  • 3.Apply && Save

5.Email Configure

1
2
3
4
5
6
SMTP server: smtp.qq.com
SMTP Port: 465
Default user E-mail suffix: @qq.com
Default Content Type: HTML(text/html)
username: **@qq.com
password: ****

6. Automatic build

  • 1.settings => Developer settings => Personal access tokens => select scop repo admin:repo_hook => copy token
  • 2.system settings => Github Server => add credentials => select secret text => secret field input token => check manage hook
  • 3.project => settings => Webhooks => check webhook setting http://*****:8080/github-webhook/

7.Publish

    1. system settings => Publish over SSH
      1
      2
      3
      4
      5
      6
      7
      name: aws
      Hostname: XXX.XX.XX.XX
      Username: root
      Remote Directory: /usr/local/nginx/

      check Use password authentication, or use a different key
      Passphrase / Password: ******
    1. project => settings => after build => send build artifacts over SSH
      1
      2
      3
      4
      Name: aws
      Source files: dist/jenkins-test/*
      Remove prefix: dist/jenkins-test
      Remote directory: html/