Demo-Test-NodeJS-Nginx 约定不等于承诺〃 2024-04-03 10:21 59阅读 0赞 /* //==========通用变量信息========= def GitAddr = "https://git.nercoa.com/fz/other/uc/sprout.git" def Branch = "master" def ImageTag = "v1.0.0" def Project = "vue-nodejs" def App_name = "backstage" def PortNumber "38081" //====================以上变量可在新建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: '973c9a08-4d62-4f8a-8792-7a214b7ffe66', 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('TestEnv') { //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('TestEnv') { sh ''' REPOSITORY=harbor.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 harbor.nercoa.com -u admin -p Nerc.nerc/1 docker push $REPOSITORY rm -rf * ''' } } //阶段4:部署到远程Node Docker主机节点 stage('Deploy To The Test Server') { node('TestEnv') { sh ''' REPOSITORY=harbor.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=harbor.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 ''' } } */ ![image.png][] ![image.png][image.png 1] ![image.png][image.png 2] ![image.png][image.png 3] #### V2 #### /* //==========通用变量信息========= def GitAddr = "https://git.nercoa.com/fz/other/uc/sprout.git" def Branch = "master" def ImageTag = "v1.0.0" def Project = "vue-nodejs" def App_name = "backstage" def PortNumber "38081" //====================以上变量可在新建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: '973c9a08-4d62-4f8a-8792-7a214b7ffe66', 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('TestEnv') { //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=harbor.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 harbor.nercoa.com -u admin -p Nerc.nerc/1 docker push $REPOSITORY rm -rf * ''' } } //阶段4:部署到远程Node Docker主机节点 stage('Deploy To The Test Server') { node('TestEnv') { sh ''' REPOSITORY=harbor.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=harbor.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 ''' } } */ [image.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/03/1e560bd47d3b4605920cd8ddce69e681.png [image.png 1]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/03/abbc8b2fa849416085958ae45de8c588.png [image.png 2]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/03/b2004cde9b9140bbb9c52bcb4304e19b.png [image.png 3]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/03/fdc11d5e1bcd4eb1aea2c03a90f6ea52.png
还没有评论,来说两句吧...