A, goals,

  • Set up gitLab private server and migrate the project
  • Build maven private server
  • Based on private server, configure Jenkins to realize automatic deployment

Ii. Build gITLab private server

1, set up
# depends on:
sudo yum install -y curl policycoreutils-python openssh-server

# Start SSH service & set it to boot at startup
sudo systemctl enable sshd
sudo systemctl start sshd

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

# download
sudo yum install -y gitlab-ce

# The icon appears indicating success
/etc/gitlab/gitlab.rb
vi /etc/gitlab/gitlab.rb

The default site Url configuration item
external_url 'http://gitlab.example.com'
The default port is 80
nginx['listen_port'] = 91

Reconfigure and start
sudo gitlab-ctl reconfigure

Copy the code
2. Migrate projects, include branches, and submit records
# Clone from the old site
git clone --bare [email protected]/groups:test.com.git
# push to new address
git push --mirror [email protected]:newgroups/newtest.com.git
Change the local URL to the new URL
git remote set-url origin [email protected]:newgroups/newtest.com.git
Copy the code
3. Reference Links:
https://cloud.tencent.com/developer/article/1333790
http://www.luyixian.cn/news_show_9166.aspx
Copy the code

3. Build Maven private Nexus server

1, set up
# official website downloadhttps://www.sonatype.com/download-oss-sonatype nexus - 3.13.0-01 - Unix. Tar. Gz# decompressionTar -zxvf apache-3.5.2-bin.tar. gz mv nexus-3.6.0-02 /usr/local/
cd /usr/local/ nexus - 3.6.0-0.2 / bin# start
./nexus start
Copy the code
2, create a private server
  • Create a private server Ihhb_repository, of type Hosted, for storing dependent jars, the release repository for internal projects
  • To create a private server Ihhb_snapshot, hosted type, Version Policy select SNAPSHOT, Deployment Policy select Allow Redeploy. Used to store snapshots
  • Modify maven-public default, group type, build central repository that depends on Aliyun, private repository
  • Create aliyun-repository, proxy type, download from Aliyun

3. Manually upload the SNAPSHOT

The jar with the end of -snapshot cannot be uploaded through the page. It needs to be configured in the project POM file or manually uploaded. Here, because there is no source code, only jar can be uploaded manually.

# modify and run the command,MVN deploy:deploy-file -DgroupId=com.ucf.um -DartifactId=visa -Dversion=1.0.12-SNAPSHOT -Dpackaging=jar - Dfile = C: / Users/chenyd/Desktop/visa/visa / 1.0.12 - the SNAPSHOT/visa - 1.0.12 - the SNAPSHOT. The jar - Durl = http://172.20.0.10:8081/repository/Ihhb_snapshot/ - DrepositoryId = maven - the snapshot# explainDurl should be the SNAPSHOT repository, and DrepositoryId should be the account ID configured in the setting fileCopy the code
4. Write the setting file

Note * * *

  • Incorrect Servers may cause a snapshot upload authentication error
  • ActiveProfiles must be written,
  • Mirrors configures a repository, a snapshot repository

*** The snapshot cannot be downloaded

  • The setting file is incorrectly configured

The project started normally, but idea Maven project reported an error

  • Re-open the POM project
<! -- Maven configuration file --> < Settings > <! --> <mirrors> <mirror> <! --This sends everythingelseTo/public - > < id > maven - public < / id > < mirrorOf > * < / mirrorOf > < url > http://172.20.0.10:8081/repository/maven-public/ < / url > </mirror> <mirror> <! --This sends everythingelseto /public --> <id>maven-snapshot</id> <mirrorOf>Ihhb_snapshot</mirrorOf> The < url > http://172.20.0.10:8081/repository/Ihhb_snapshot/ < / url > < / mirror > < / mirrors > < profiles > < profile > <id>development</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled>
					
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>central</id>
					<url>http://central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <! --this profile will allow snapshots to be searched when activated--> <id>Ihhb_snapshot</id> <repositories> <repository> <id>Ihhb_snapshot</id> <url>http://Ihhb_snapshot</url> <releases> <enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>Ihhb_snapshot</id>
					<url>http://Ihhb_snapshot</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>Ihhb_snapshot</activeProfile>
	</activeProfiles>
	<localThe Repository > / data/apache maven - 3.6.1 track/maven_repository < /localRepository> <! -- Publish server and password, temporarily unlimited permissions, Maven-public </id> <username>admin</username> <password>admin123</password> </server> <server> <id>maven-snapshot</id> <username>admin</username> <password>admin123</password> </server> </servers>  </settings>Copy the code

4. Configure Jenkins

1, install,
# official website download
https://jenkins.io/download/

# You can start tomcat, or you can directly start tomcat, and change the port
java -jar jenkins.war --ajp13Port=-1 --httpPort=8090

Access with a newbie install
Copy the code
2, configuration,

Installing a plug-in

Git Plugin is required to Deploy git according to target. Need Dynamic Parameter plug-in plug-in, in this plug-in download not, CSDN, here to provide free network backup link: https://pan.baidu.com/s/1hvl_URW8s1mvLIRv1jFhUg extraction code: rnw7Copy the code

Modifying system Settings

SSH Login ConfigurationLog in to the server to generate the key
ssh-keygen
Send the public key to the desired serverSsh-copy-id -i /root/.ssh/id_rsa.pub root@ Host IP address of the target server# landingSSH root@Host IP address of the target serverCopy the code

Modified global tool configuration

Modify the setting

3. Create projects

Building a Maven project

Keep a record of 2 builds

Git source code

Server-generated key pair, private key used for GitLab file creation

The public key is used to add credentials

Maven packaging skips testing and selects the compiled environment

A script executed after compilation

Scripts on the target server

For some reason, the package Jenkins built was not uploaded to the remote server, so a script was written to transfer and boot.

echo "Switch to project address"
cd /apps/product/exch

echo "Close the exch-platform.jar process"
ps -ef|grep java|grep exch-platform.jar|awk '{print $2}'|xargs kill9 -echo "Delete package"
rm -rf exch-platform.jar

echo "The package"SCP [email protected]: / root /. Jenkins/workspace/exch - test - 0.13 / exch_platform/target/exch - platform. The jar/apps/product/exchecho "Start"/apps/product/jdk1.8.0_181-amd64/bin/ Java -jar exch-platform.jar > nohup.out &echo "Complete"
Copy the code

Note * * *

  • Since the jar package is started, the nohup command in the script will cause the foreground to print logs, which will eventually be the same as time out. Therefore, nohup sh /apps/ Jenkins /exch.sh is used to start the service, and the command is > nohup.out &, which ensures that the log data and the service will not be killed by Jenkins.
  • Nohup does not hang up, & background runs

The final results

update

The reason there is no automatic package transfer to the remote server is because I only care that the address logged in after the build is on the path configured for SSH login to the server. Unconcerned, the packaged file path is the relative path of the workspace. Automatic packet transmission succeeds after the path and prefix of the file are changed.