This POST is about building a JENKINS+GITHUB CONTINUOUS integration environment from scratch. JENKINS ‘integration with other platforms, such as the code cloud, is similar. Next, we explain it STEP BY STEP. If there are any unreasonable points, please point out the ☞

Buying a server

Why buy a server?

Because if you set up the Jenkins environment locally, you will not be able to connect to Github — you need IP to set githubWebhooks. Of course, what other operations can be connected to github, please point out 🙂

Note: if you’re running locally Jenkins, then your webhooks may be https://localhost:8080/github-webhook/, it won’t work, because webhooks only play a role in the network. You can check out Adding a GitHub Webhook in Your Jenkins Pipeline.

Here, I bought ali cloud’s low-configuration server, operating system is centos7. After purchasing the server, I simply proxy it through NGINX and present a simple static page. Of course, this is not our focus, so I won’t go into it.

It is important to note that you need to configure security groups to see static sites. My own configuration is shown as follows:

After uploading the resource, at this point you open the relevant IP address on the Cloud. If you do not see the page you expected, please check the security group Settings.

Prepare a terminal

Why prepare?

We can’t always log in to our Aliyun account, switch to our own server, connect to it, and then run the app

If you like it, keep it that way. Let’s just say you have a lot of time

Here, I’ve installed SecureCRT (a terminal emulator that supports SSH(SSH1 and SSH2)) on both MAC Pro and Dell computers to remotely control my servers. I think very good use, like! ❤

Setting up JENKINS environment

The server and remote control simulation program are ready to complete, next, we set up the required environment on the server.

Installing the Java Environment

Install the Java environment on the server as described in this article. After installing the Java SDK, configure the environment.

After that, you can run the Java -version command to view or verify the Java installation information and related path Settings on your server:

The /usr/lib/java directory is the directory where the JDK-8U231-linux-x64.tar. gz compressed file is uploaded to the server. You can delete the compressed file after decompressing it.

/usr/java/java8 is the path to decompress the files on the server.

Install Jenkins

Follow the following command line:

$ yum install yum-fastestmirror -y  Install the plugin that automatically selects the fastest source
# Add Jenkins source:
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
$ yum install jenkins               # installation Jenkins
Copy the code

Once installed, you can start Jenkins:

sudo service jenkins start
Copy the code

Of course, after startup, it may have the following problems:

The graph shows that there is a problem with your Java import path

The launcher could not find Java.

D/Jenkins/vim /etc/init.d/ Jenkins

Note: Linux using the find. | xargs grep – ri command search “to find the string” contains a string of files

After a successful startup, the console has a success reminder. At this point, you can open the browser http://your server IP :8080, display information as shown below. The default Jenkins port number is 8080, of course, you can run vim /etc/sysconfig/jenkins file to change the port number, etc.

Same as above, if the page cannot be opened, please check whether you have set up a security group in Ali Cloud ~

Well, the next step is to unlock Jenkins.

The use of Jenkins

We were able to successfully install and run Jenkins on our own service. Now let’s upgrade and use Jenkins.

unlock

According to the prompt, we implement the cat/var/lib/Jenkins/secrets/initialAdminPassword command to get the Administrator password, then click the continue button, go down.

We choose to install the recommended plug-in and wait for it to complete. If there are plug-ins that fail to be installed, you can skip them and install them as required. [Please keep the network smooth during installation]

Example Initialize the account and password

You can create your own admin user information, or click on the link to continue using admin and skip it.

After setting, enter the interface:

Associated with making

Our goal is to combine Github and Jenkins for automated distribution. Now let’s associate github. The following uses my Github account as an example.

To generate the secret text

Secret Text is called token on Github.

Go to Github –> Settings –> Developer Settings –> Personal Access Tokens –> Generate new tokens

Then generate a new token:

Fill in the name of Toke, check the two boxes above, and then press the Generate Token button to confirm:

Save the token for yourself. If you lose it, you will never find it again.

Set the lot webhooks

Then, choose their own a lot project, here I take his blog https://github.com/reng99/blogs warehouse as an example:

Go to the specified project on Github –> Settings –> Webhooks –> Add Webhooks –> enter the IP address of the server where Jenkins was just deployed

Payload URL http://your IP :8080/github-webhook/

Jenkins’ Github configuration

After installing the Github Plugin correctly, let’s configure the Github Plugin. If you haven’t already installed the Github Plugin, go to System Administration > Plugins Management > Optional Plugins to install it. Jenkins has already done this for you.

The Github plugin is installed by default

Configuration is making the Plugin

System > System Settings > GitHub add GitHub server

As shown below:

Enter https://api.github.com for API URL, click Add for credential Credentials, and select Secret Text for type, as shown below:

Click the Add button, and select the credential you have added. Then click the Connection Test button. When the information on the Credentials Verified for user XXX, Rate Limit: XXX is displayed, it indicates that the credential is valid.

Create a Freestyle task

Go to the home page –> Create a task

General Settings

Fill in making project URL, that is, your home page, https://github.com/your_name/your_repo_name, I use my blog here warehouse to try https://github.com/reng99/blogs

Configure source code management

After checking the Git option, you will see the related fields to fill in. Just follow the instructions below

  1. Enter the git address of the project, eg:https://github.com/your_name/your_repo_name.git
  2. Add a Github user and password (for a Github account with write permission, see the following figure)
  3. Select the GithubWeb source library browser and fill in your project URL so that each build will generate the corresponding changes and you can link directly to Github to see the details

Click Add to add the Credentials:

Build trigger

Select GitHub hook Trigger for GITScm polling

Build environment Configuration

Select Use secret test(s) or file(s)

Set up the binding

Select Bind –> Click the Add button –> Select Secret Text –> drop down to select the Secret Token you set up –> Apply later

Setting up the build

I haven’t done much here, so you can script the build according to your own needs.

Post-build operation

You can change the post-build operations as required, and I’m default here.

Build validation

After the above work is completed, modify the code of my Blogs warehouse and refresh my Jenkins address after submission. The following phenomenon shows that it is successful ~ (PS: The first time to build is time-consuming, please wait patiently and refresh the page from time to time)

Error handling

During the integration process, you may encounter the following problems

Reinstall the plug-in

Some plug-ins may fail to be installed during initialization. However, don’t worry, you can come in and install any plug-ins you want.

After the installation is successful, go to the /restart/ path to restart Jenkins.

It is normal to enter again, pleasurable ~

The git command error

Check whether Git is installed on the server

# git version
Copy the code

If git is not available, you need to install it.

# yum install git
Copy the code

The build trigger could not find the Github option

[Bug Mc-10807] – option Build when a change is pushed to Github not found when building trigger

That’s because the new Jenkins has changed it to GitHub hook trigger for GITScm polling.

The latter

  • First article: github.com/reng99/blog…
  • More: github.com/reng99/blog…