Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Build and publish ordinary websites (jenkins+ngin) through jenkins

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This lab introduces:

Nginx:web website

Svn: code storage repository

Jenkins: automated operation and maintenance tool

The developer submits the code to svn, and the operator automatically publishes it to the nginx directory by configuring jenkins.

Experimental environment:

192.168.0.188 Jenkins

192.168.0.189 nginx

192.168.0.19 svn

Jenkins, nginx and svn environments are all ready to be completed, and there is no need to build them again.

Steps:

1.Jenkins installs the ssh plug-in and configures the remote server

two。 Set up a project (job) to configure Jenkins

3. Upload the code to svn

4. Publish files with Jenkins

5. View test results

1.Jenkins installs the ssh plug-in and configures the remote server

In Jenkins system management-plug-in management

Select the plug-in publish over ssh plug-in and install it, ignore if it is installed

Start to configure system management-system configuration after installation

Scroll to the back, find the SSH Servers option and add

The test can be connected and saved.

Interpretation:

SSH Server is configured as the configuration of the operator in Publish Over SSH, which is divided into two parts: basic Settings and Advanced Settings. Basic Settings are mainly operating machines IP, SSHusername, SSHport, connection timeout, and so on. Advanced Settings have the same options as most Global Settings.

Name: create the name of this machine

Hostname: address of the remote machine, preferably ip address

Username: user name

Remote Directory: remote directory

Use password authentication, or use a different key: connect with password

Advanced Settin

Advanced settings allow you to set SSHport, retry time, and once again set the options in Global Settings

Global configuration:

Each item can be overridden by SSH Server settings, and this design has an advantage. In the case that the server environment is better than the specification, the tedious steps of configuring each SSH Server separately can be saved.

Parameter description

Password of Passphrase:SSH

The password of username when logging in using username/password. The password that is the private key when logged in with the private key.

File path of Path to key:SSH private key

The path to the private key file, which can be absolute. It can also be a relative path to $JENKINS_HOME

Key: private key

The text content after the private key is exported

Extended example: what should I do if I use a secret key to connect remotely instead of a password? the server where the 1.jenkins resides generates a public-private key pair 2. Transfer the public key (idrsa.pub) to the machine to be remote or enter the contents of the public key into the remote machine authorizedkeys file (/ root/.ssh/authorizedkeys) chmod 600 / root/.ssh/authorizedkeys3.jenkins to set the path file where the private key is located, and enter the password to generate the public and private key (Passphrase/Password field requires entering the public and private key password) (enter the path of the private key file of the server where the jenkins resides in the Path to key field)

Assuming that both "Key" and "Path to key" are set, "Key" has a higher priority, and the password of the private key is set in "Passphrase".

Disable exec: disable running commands on the target machine

When checked, commands set in the "Exec command" option in the Job configuration will be ignored. "The Disable exec in the advanced settings for individual configurations will be ignored." in the documentation of Jenkins. I don't fully understand. From a practical point of view, only after "Disable exec" is checked, no matter whether "Disable exec" is checked in SSH Server or not. Commands set in Job are ignored.

two。 Set up job task

Click New Task

Enter a name, select a free style project, and then determine

Select svn for source code management

Among them

Repository URL: svn address of the project

Credentials: credential

Click add and add the corresponding user name

Select post-build action and select send build artifacts over SSH

Description of parameters:

Name

List of names of the SSH Sverver for the system Administration > system Settings setting.

Source files

A file copied to the operating machine. Relative to the path of workspace, expressions are also supported, such as "* / .war" in the figure above.

Remove prefix

The folder to be filtered when copying files, such as the target folder in the figure above.

Remote directory

The file gets to the folder on the remote machine, which is relative to "Remote directory" in "SSH Server". Assuming it does not exist, it will be created on its own initiative.

Exec command

Here you can fill in the scripts that run on the running machine, such as the application deployment script

Here, you can copy the svn publishing file directly to the nginx publishing directory, or you can modify the remote directory, and then run the command to copy it to nginx. This method is more secure.

This is before the release of nginx.

Modify the file and transfer the file to svn

Click to build

View the log

Refresh the page and publish successfully

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report