jenkins+svn+nodejs自动构建发布代码

流程:jenkins从SVN获取数据到jenkins的workspace,通过nodejs打包后将打包后的BUILD文件通过SHELL脚本传到SVN代码库上,完成这些操作,如下图:



1.    安装nodejs插件
点击系统管理-插件管理,搜索NodeJS并安装



2.    设置
点击系统管理-全局工具设置,找到nodejs




3,
新建任务,选择构建一个自由风格的软件项目


二、项目配置

  配置SVN源:


在构建环境中设置环境为node环境


 


 

cat /server/shell/html_test.sh

#!/bin/bash

BUILD_ID=$1

echo "change to jenkins workspace"

cd /var/lib/jenkins/workspace/html_test/

echo "install node packages"

npm i

echo "modify package.json file"

sed -i 's/rd\/s\/q build/rm -rf .\/build/g' package.json

echo "packing"

npm run build

 

if [ $? -eq 0 ]; then

 

echo "delete old svn build files"

cd /usr/local/src/svn_upload/html_test/

svn delete ./*

svn commit -m "delete old build version:$(expr$BUILD_ID - 1) files from svn repos"

 

echo "copy build file to html_test directory"

cp -rf /var/lib/jenkins/workspace/html_test/build/* /usr/local/src/svn_upload/html_test/

 

echo "add news files to svn"

svn add ./*

svn commit -m "add new build  version:$BUILD_IDto svn repos"

 

echo "Start to delete Jenkins workspacehtml_test"

cd /var/lib/jenkins/workspace/html_test/

rm -rf ./*

echo "Delete Jenkins html_test of files OK"

echo "Last Build Number is:$BUILD_ID"

fi

 

 

 

 

 

 


分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS