Jenkins - 项目配置(前端)
构建 - Execute shell
bash
yarn config set registry https://registry.npm.taobao.org -g
source /etc/profile
case $Project in
PC)
echo "Project:$Project"
path="${WORKSPACE}/pc"
cd $path
yarn install
yarn run build
\cp -rf dist /usr/Web/xxxx/pc
tar -zcvf ./html.tar.gz ./dist/*
\cp html.tar.gz ${WORKSPACE}/new
cd ${WORKSPACE}
tar -zcvf ./new.tar.gz ./new/*
;;
H5)
echo "Project:$Project"
path="${WORKSPACE}/h5"
cd $path
yarn install
yarn run build
\cp -rf dist /usr/Web/xxxx/h5
tar -zcvf ./h5.tar.gz ./dist/*
\cp h5.tar.gz ${WORKSPACE}/new
cd ${WORKSPACE}
tar -zcvf ./new.tar.gz ./new/*
exit
;;
esac
构建后操作 - Send build artifacts over SSH
Exec command
bash
cd /usr/XXXX/Web/bak
mkdir "$(date +%Y-%m-%d-%H-%M)" && mv -f ../html "$(date +%Y-%m-%d-%H-%M)"
cd /usr/XXXX/Web
tar -zxvf new.tar.gz
cd /usr/XXXX/Web/new
tar -zxvf h5.tar.gz
mv dist h5
tar -zxvf html.tar.gz
mv dist html
mv -f h5 html
mv -f html /usr/XXXX/Web
#保留5个备份
ReservedNum=5
FileDir=/usr/XXXX/Web/bak
date=$(date "+%Y-%m-%d-%H-%M")
cd $FileDir
FileNum=$(ls -l | grep '^d' | wc -l)
while(( $FileNum > $ReservedNum))
do
OldFile=$(ls -rt | head -1)
echo $date "Delete File:"$OldFile
rm -rf $FileDir/$OldFile
let "FileNum--"
done
Jenkins - 项目配置(后端-java)
1.General-描述
xxx系统后端发版
2.源码管理
Repository URL:
ruby
http://127.0.0.1:8080/xxxx/java-service/xxx-system.git
Credentials
Branches to build
指定分支
3.构建触发器
不设置
4.构建环境
选择Add timestamps to the Console Output
4.1 Pre Steps
不设置
4.2 Build
4.2.1 Root POM
pom.xml
4.2.2 Goals and options
ini
clean package -Dmaven.test.skip=true
4.2.3 Post Steps
选择 Run only if build succeeds
5. 构建后操作
5.1Send build artifacts over SSH
SSH Server 下拉选择服务
Transfers Transfer Set Source files
perl
xxxx-system-starter/target/xxxx-system-starter-1.0.0-SNAPSHOT.jar
Remote directory
bash
/usr/XXXX/java
Exec command
bash
cd /usr/xxxx/java/bak
mkdir "$(date +%Y-%m-%d-%H-%M)" && mv -f /usr/xxxx/java/xxxx-system-starter-1.0.0-SNAPSHOT.jar "$(date +%Y-%m-%d-%H-%M)"
cd /usr/xxxx/java/
cp -r xxxx-system-starter/target/xxxx-system-starter-1.0.0-SNAPSHOT.jar /usr/xxxx/java
rm -rf xxxx-system-starter
/usr/xxxx/script/xxxx-system.sh
#保留5个备份
ReservedNum=5
FileDir=/usr/xxxx/java/bak
date=$(date "+%Y%m%d-%H%M%S")
cd $FileDir
FileNum=$(ls -l | grep '^d' | wc -l)
while(( $FileNum > $ReservedNum))
do
OldFile=$(ls -rt | head -1)
echo $date "Delete File:"$OldFile
rm -rf $FileDir/$OldFile
let "FileNum--"
done
Jenkins - Maven Settings
xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>org.jenkins-ci.tools</pluginGroup>
</pluginGroups>
<!--配置权限,使用默认用户-->
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>XXXX</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.8</jdk>
</activation>
<repositories>
<!-- 私有库地址-->
<repository>
<id>nexus</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>nexus</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活profile-->
<activeProfiles>
<activeProfile>XXXX</activeProfile>
</activeProfiles>
</settings>