/*
//==========通用变量信息=========
def GitAddr = "https://git.nercoa.com/fz/other/uc/Sprout_2021.git"
def Branch = "develop/rpet_v1"
def ImageTag = "v1.0.1"
def Project = "vue-nodejs"
def App_name = "backstage"
def PortNumber "8005"
//====================以上变量可在新建Job任务时使用字符参数进行插入=====================
*/
//Job Start!!
//阶段1:拉取代码,node 节点未指定,则在Master执行,因为Git、Maven 环境都在 Master,所以就在主节点执行了
stage(' Git Checkout') {
node('MSBuild') {
checkout([$class: 'GitSCM', branches: [[name: '${Branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '8888888-8888-8888-8888-888888fe66', url: '${GitAddr}']]])
}
}
//阶段2:Dotnet编译代码
stage('Build'){
node('MSBuild') {
echo '编译解决方案'
bat "cd src/${App_name} && npm install && npm run build"
}
}
stage('Backup To The Site Directory'){
node('MSBuild') {
// dir('dist') {
bat "cd src/${App_name} && zip -r ${BUILD_NUMBER}.zip dist/*"
// }
echo '拷贝文件至备份目录'
bat "echo d | xcopy /e /y /r /f src\\${App_name}\\${BUILD_NUMBER}.zip \"${BACKUP_SHARE_DIR}/${JOB_NAME}/\""
bat "rm -rf src\\${App_name}\\dist && rm -rf src\\${App_name}\\*.zip"
}
}
stage('Download Project Code'){
node('Container') {
//echo '建立业务目录' #会在 workspace 下自动创建任务目录
//sh "mkdir -p ${JOB_NAME} && cd ${JOB_NAME}"
echo '下载程序'
sh "curl -O http://rls.nercoa.com/${JOB_NAME}/${BUILD_NUMBER}.zip"
echo '解压源程序'
sh "unzip -o *.zip && mv -f dist/* ./ && rm -rf *.zip dist"
}
}
//阶段3:构建Docker镜像并推送到私有仓库
stage('Build And Push Image') {
node('Container') {
sh '''
REPOSITORY=hub.nercoa.com/${Project}/${App_name}:${ImageTag}
cat > Dockerfile << EOF
#注意选择镜像镜像版
FROM nginx
MAINTAINER WinJayX <WinJayX@Gmail.com>
LABEL description="This is NodeJS Project"
LABEL version="0.1"
USER root
COPY . /usr/share/nginx/html
EOF
docker build -t $REPOSITORY .
docker login hub.nercoa.com -u username -p password
docker push $REPOSITORY
rm -rf *
'''
}
}
//阶段4:部署到远程Node Docker主机节点
stage('Deploy To The Test Server') {
node('Container') {
sh '''
REPOSITORY=hub.nercoa.com/${Project}/${App_name}:${ImageTag}
docker rm -f ${App_name} || true
docker container run -d \
--volume /etc/localtime:/etc/localtime:ro \
--restart always \
--user root \
--name ${App_name} \
--hostname ${App_name} \
-p ${PortNumber}:80 $REPOSITORY
'''
}
}
/*
//阶段5: 获取站点的状态
stage('Test the WebSite') {
node('Node12') {
sh '''
curl -I -m 10 -o /dev/null -s -w %{http_code} 202.205.161.114:39096
'''
}
}
stage('Deploying To The Production Server'){
timeout(time: 1, unit: 'DAYS') {
input message: 'Deploying To The Production Server?', ok: 'Deployment'
}
}
//阶段6:部署到生产环境服务器,||true 短路逻辑运算,只有前面返回假echo $? =1 时,后面才执行
stage('Deploy To The Production Docker Server') {
// 方式1 执行远程服务器上的脚本文件
// node {
// sh '''
// ssh root@202.205.161.131 "cd /home/docker/003.CourseDetectionWeb ; sh docker_CourseDetectionSystem.start.sh"
// '''
// }
//方式2
node('Node12') {
sh '''
cd /home/Docker/009.FZ.VR.Authorizationsystem
REPOSITORY=hub.nercoa.com/fz_vr/authorization:${ImageTag}
docker rm -f VR_Auth || true
docker container run -d \
--volume /etc/localtime:/etc/localtime:ro \
--volume `pwd`/Config:/app/Config \
--restart always \
--user root \
--name VR_Auth \
--hostname VR_Auth \
-p 8009:80 \
$REPOSITORY
'''
}
}
*/
评论区