This article will briefly introduce how to configure Jenkins+ GitLab continuous integration build process in Linux

Goal:

  1. Can build successfully and publish to the test environment
  2. Gitlab pushes the specified branch code to trigger the build
  3. Set up developer email notifications

process

  1. The Linux foundation
  2. Environment: Java Node Jenkins Git YARN Note: Configure global environment variables
  3. Jenkins configuration
  4. Gitlab – > webhook configuration
    • Webhook: The Webhook plugin allows you to set up or subscribe to certain events on GitLab. When one of these events is fired, we send an HTTP POST payload to the webhook configuration URL. Webhooks can be used to update external problem trackers, trigger CI builds, update backup images, and even deploy to production servers.

The Linux foundation

  • The command
    • PWD: View the current directory
    • Vi directory: Go to edit the directory
      • esc + : + q + ! : Forcibly exits without saving
      • Esc + : + w + q: Save the configuration and exit
    • Source /etc/profile: The modified /etc/profile file takes effect immediately
      • Shift + G: Go to the bottom of the file
      • Mv Original name New name: renamed
    • Yum command

steps

Software installation

wget

yum install wget
Copy the code

unzip

yum install unzip
Copy the code

nodejs

  • View the Linux system bits
uname -a
Copy the code

  • Go to the installation directory (/usr/local/src)

  • Download the installation package

Wget HTTP: / / https://nodejs.org/dist/v8.5.0/node-v8.5.0-linux-x64.tar.xzCopy the code
  • Unzip and enter
The tar - ZXVF node - v8.5.0 - Linux - x64. Tar. XzCopy the code

Z: has the gzip attribute x: unzip v: shows all procedures f: uses the file name, this parameter can only be placed last

  • Configuring global variables
    • Edit the /etc/profile file
    • Add the following code to the end of the file to save and exit the file
export NODE_PATH=/usr/local/ SRC/node - v8.5.0 - Linux - x64 / binexport PATH=$PATH:$NODE_PATH	
Copy the code
  • Verify that a global variable is configured
node -v
npm -v
Copy the code

yarn

NPM install - global [email protected]Copy the code

java

  1. The installation
wget http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz?AuthPa ram=1521104652_72aaa3f990b00fe806f0156100c8c245Copy the code
  1. rename
mv jdk-8u161-linux-x64.tar.gz? AuthParam=1521104652_72aaa3f990b00fe806f0156100c8c245 java-jdk.tar.gzCopy the code
  1. Unpack the
tar xzf java-jdk.tar.gz
Copy the code
  1. Configuring global variables
export JAVA_HOME=/usr/local/ jdk1.8.0 _91export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Copy the code

git

  • Download, compress, and go to the directory
Wget https://github.com/git/git/archive/v1.7.1.zip unzip v1.7.1. ZipcdGit - 1.7.1Copy the code
  • Install the required plug-ins
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
Copy the code
  • Compile, install
make prefix=/usr/local/git all
make prefix=/usr/local/git install
Copy the code
  • Configure global environment variables
    • Edit/etc/profile
    • Add the following code to the end of the file to save and exit the file
export PATH=/usr/local/git/bin:$PATH
Copy the code
  • Configure git
    • Set user to generate an SSH key
git config --global user.name "xxx"
git config --global user.email "mailto:[email protected]"
ssh-keygen -t rsa -C "mailto:[email protected]"
Copy the code
  • Add the SSH key generated above to GitLab
cat ~/.ssh/id_rsa.pub
Copy the code

Copy the content with sSH-RSA in the header

Jenkins

Wget HTTP: / / http://updates.jenkins-ci.org/download/war/2.109/jenkins.warCopy the code

Jenkins + GitLab configuration

Jenkins Configuration (1) === is recommended

  • Start the Jenkins
nohup java -jar /root/app/jenkins.war --httpPort=8080 2>&1 &
Copy the code

& : When a job is run in the foreground, the terminal is occupied by the job; Background nohup can be implemented by adding & to the command: When the & command is used, the job is submitted to the background. The current console is not occupied, but the job is stopped when the current console is turned off (when the account is logged out). The nohup command allows the process to continue running after the user exits the account. Note: 1. Enter a secret key (as seen in Xshell) for the first startup. 2. The default admin password in the login. Jenkins/secrets/initialAdminPassword file (use) the next logon. 3. You can also change the password

  • Create a new project
  • Jenkins configuration hookplugin
    • Install plug-in: Gitplugin, GitLab, GitLab Plugin, GitLab Hook Plugin, Build Authorization Token, gitlab Authorization
    • Project configuration
      • General: Enter the project name
      • Source code management:
      • Build triggers:
        • Regular filtering triggers branching
        • Record the url
        • Record the token
  • Write package command

Jenkins Configuration (2) ===

  • Random token generation
openssl rand -hex 12
Copy the code

A string of tokens is generated and saved

  • Build trigger
    • Check ‘Trigger remote build (for example, using scripts)’ and enter the randomly generated token in the authentication token bar: saved above
      • Record the url
    • Check ‘Gitlab hook Trigger for gitScm Polling’

Gitlab configuration

  • Add the SSH key
  • Configuration webhook
    • Select project –> Setting –> Webhook
    • Fill in the URL saved above
    • Fill in the token saved above
    • Add webhook
    • Test (Test whether the process can run)
      • Error 403, not logged in, fix url ‘http://’ ‘with username: password
      • No valid crumb was included in th request. Go to Jenkins System Management > Global Security Configuration > Uncheck: Prevent cross-site request forgery

Jenkins email notification configuration

  • System Management > System Settings

    • Set the email address of the administrator
    • Extended E-mail Notification
      • ‘Allow sending to unregistered Users’ is not selected.
      • After the selected:
    • Email notification
      • You can send a test email to see if it’s successful
  • Project Settings

    • To add post-build steps, select E-mail Notification, Editable E-mail Notification
    • E-mail Notification
    • Editable E-mail Notification– >Advances Settings, add Triggers