侧边栏壁纸
博主头像
★街角晚灯★ 博主等级

博观而约取 厚积而薄发

  • 累计撰写 468 篇文章
  • 累计创建 185 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Jenkins-Test

WinJay
2022-03-01 / 0 评论 / 0 点赞 / 84 阅读 / 0 字 / 正在检测是否收录...

示例1

pipeline{
//老项目
    agent  { node { label 'MSBuild' } }
    
    environment {
        //GIT 认证标识
        GIT_AUTH = "973c9a08-4d62-4f8a-8792-7a214b7ffe66"
        //GIT 地址
        GIT_URL = "https://git.nercoa.com/fz/NewTeacherNet.git"
        //GIT 分支
        //GIT_BRANCHE = "develop/2.0"
        // 解决方案路径或目录
        SLN_File = "src/ULearning_V2/"
        //项目名称
        PROJECT_File = "src/ULearning_V2/ULearning.WebSite"
        //源码编译输出的目录
        BUILD_OUTDIR = "\"D:\\002.ReleaseCode\\${JOB_NAME}\\${BUILD_NUMBER}\""
        //测试服务器节点
        TEST_0_NODE = "Web1"
        //测试部署目录
        TEST_0_DEPLOYDIR = "D:\\Web_Test\\NewTeacherNet\\ULearning_V2"
        //测试环境发布后的校验地址
        TEST_URL = "http://202.205.161.103:9308"


        //生产环境备节点
        PROD_1_NODE = "App04"
        //生产环境部署目录
        PROD_1_DEPLOYDIR = "\"D:\\WebSite\\NewTeacherNet\\Ulearning\""
        //生产环境发布后的校验地址
        PROD_1_URL = "http://www.newteach365.com/web/index.aspx"


        //生产环境主节点
        PROD_0_NODE = "App00"
        //生产环境部署目录
        PROD_0_DEPLOYDIR = "\"D:\\WebSites\\002.FanZai_ULearning\\002.FanZai_ULearning\""
        //生产环境发布后的校验地址
        PROD_0_URL = "http://39.96.88.11:8002"


    }
    
    stages{
         stage('拉取更新'){
               steps{
                  echo '检测代码更改'
                  checkout([$class: 'GitSCM', branches: [[name: "$GIT_BRANCHE"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "$GIT_AUTH", url: "$GIT_URL"]]])
               }
         }
         
     stage('编译'){
                steps{
                   echo '编译解决方案'
                   bat "$NUGET %SLN_File%"
                   bat "$MSBUILD %SLN_File% /t:Compile /p:Configuration=Release"
                   bat "$ASPNET_COMPILER -v %PROJECT_File% -p %PROJECT_File% -u -f %BUILD_OUTDIR% "
                }
         }
         
         stage('版本备份'){
                 steps{
                     bat  "$ASPNET_MERGE %BUILD_OUTDIR% -w ULearning.WebUI.dll -a"
                     echo "构建完成 => %BUILD_OUTDIR%" 
                     echo "开始打包程序"
                     bat "cd /d %BUILD_OUTDIR% && zip -9 -r ${BUILD_NUMBER}.zip ./ && mv ${BUILD_NUMBER}.zip ../ && cd ../ && rd /s/q ${BUILD_NUMBER}"
                     echo "打包完成 => ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                  }
         }
                  
         stage('发布至测试'){
                steps{
                     node("$TEST_0_NODE") {
                         echo '下载程序'
                         bat "IF NOT EXIST \"${WORKSPACE}/download\"  MD \"${WORKSPACE}/download\" "
                         bat "curl -o download/${BUILD_NUMBER}.zip ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                         echo '解压源程序'
                         bat "unzip -o download/${BUILD_NUMBER}.zip -d %TEST_0_DEPLOYDIR% "
                    }
                }
         }
         
         stage('检测测试环境运行状态'){
                 steps{
                    bat "${JENKINS_TOOL}/test.bat %TEST_URL% "
                 }
         } 
         
        //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 Begin-----------------------------
         
         stage('是否发布至正式'){
                steps{
                     timeout(time: 1, unit: 'DAYS') {
                     input message: '是否发布至正式?', ok: '发布'
                    }
                }
         }
         
         stage('发布至正式'){
                steps{
                     node("$PROD_1_NODE") {
                         echo '下载程序'
                         bat "IF NOT EXIST \"${WORKSPACE}/backup\"  MD \"${WORKSPACE}/backup\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/temp\"  MD \"${WORKSPACE}/temp\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/download\"  MD \"${WORKSPACE}/download\" "
                         bat "curl -o download/${BUILD_NUMBER}.zip ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                         echo '备份源程序'
                         bat "cd %PROD_1_DEPLOYDIR% && zip -r \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" ./"
                         echo '解压源程序'
                         bat "unzip -o download/${BUILD_NUMBER}.zip -d \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                         bat "\"${WORKSPACE}/../../deploy.bat\" ${WORKSPACE}/temp/${BUILD_NUMBER} %PROD_1_DEPLOYDIR%"
                    }
                }
                post {
                    always {
                        node("$PROD_1_NODE") {
                            echo '清理文件'
                            bat "rd /s /q \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                        }
                    }
                 }
         }
         
         stage('检测生产环境运行状态'){
                steps{
                     bat "${JENKINS_TOOL}/test.bat %PROD_1_URL% "
                }
                post {
                    failure { 
                        node("$PROD_1_NODE"){
                                echo '发布失败,回滚该站点'
                                bat "rd /s /q %PROD_1_DEPLOYDIR% "
                                bat "unzip -o \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" -d %PROD_1_DEPLOYDIR% "
                        }
                    }
                }
         }
         
        //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 END-----------------------------


/*

        //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 Begin-----------------------------
         
         stage('是否发布至正式'){
                steps{
                     timeout(time: 1, unit: 'DAYS') {
                     input message: '是否发布至正式?', ok: '发布'
                    }
                }
         }
         
         stage('发布至正式'){
                steps{
                     node("$PROD_0_NODE") {
                         echo '下载程序'
                         bat "IF NOT EXIST \"${WORKSPACE}/backup\"  MD \"${WORKSPACE}/backup\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/temp\"  MD \"${WORKSPACE}/temp\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/download\"  MD \"${WORKSPACE}/download\" "
                         bat "curl -o download/${BUILD_NUMBER}.zip ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                         echo '备份源程序'
                         bat "cd %PROD_0_DEPLOYDIR% && zip -r \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" ./"
                         echo '解压源程序'
                         bat "unzip -o download/${BUILD_NUMBER}.zip -d \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                         bat "\"${WORKSPACE}/../../deploy.bat\" ${WORKSPACE}/temp/${BUILD_NUMBER} %PROD_0_DEPLOYDIR%"
                    }
                }
                post {
                    always {
                        node("$PROD_0_NODE") {
                            echo '清理文件'
                            bat "rd /s /q \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                        }
                    }
                 }
         }
         
         stage('检测生产环境运行状态'){
                steps{
                     bat "${JENKINS_TOOL}/test.bat %PROD_0_URL% "
                }
                post {
                    failure { 
                        node("$PROD_0_NODE"){
                                echo '发布失败,回滚该站点'
                                bat "rd /s /q %PROD_1_DEPLOYDIR% "
                                bat "unzip -o \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" -d %PROD_0_DEPLOYDIR% "
                        }
                    }
                }
         }
         
        //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 END-----------------------------

*/
         
     }
}

示例二

pipeline {
//新项目

    agent  { node { label 'MSBuild' } }
    
    environment {
    	//GIT 认证标识
    	GIT_AUTH = "973c9a08-4d62-4f8a-8792-7a214b7ffe66"
    	//GIT 地址
    	GIT_URL = "http://git.nercoa.com/fz/ZhiXinTech.git"
    	//GIT 分支
    	//GIT_BRANCHE = ""
    	// 解决方案路径或目录
    	SLN_File = "src/Exam_V2/Fz.ExamWeb/Fz.ExamWeb.sln"
    	//项目名称
    	PROJECT_File = "src/Exam_V2/Fz.ExamWeb/Fz.ExamWeb/Fz.ExamWeb.csproj"
    	//源码编译输出的目录
    	BUILD_OUTDIR = "\"D:\\002.ReleaseCode\\${JOB_NAME}\\${BUILD_NUMBER}\""
    	//测试服务器节点
    	TEST_0_NODE = "Test01"
    	//测试部署目录
    	TEST_0_DEPLOYDIR = "D:\\WebSites\\FZ_ULearning_Test\\ULearning"
    	//测试环境发布后的校验地址
    	TEST_URL = "http://202.205.161.84:9301/web/Index.aspx"


        //生产环境备节点
        PROD_1_NODE = "App04"
        //生产环境部署目录
        PROD_1_DEPLOYDIR = "\"D:\\WebSite\\NewKnowLedgeNet\\Exam\""
        //生产环境发布后的校验地址
        PROD_1_URL = "http://exam.zhixintech.com"
    }
    
    stages{
         stage('Git拉取更新'){
               steps{
                  echo '检测代码更改'
                  checkout([$class: 'GitSCM', branches: [[name: "$GIT_BRANCHE"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "$GIT_AUTH", url: "$GIT_URL"]]])
               }
         }
         
         stage('还原Nuget包'){
                steps{
                   bat "$NUGET %SLN_File%"
               }
         }
                   
         stage('版本备份'){
                steps{
                   echo '编译解决方案'
                   bat "$MSBUILD %PROJECT_File% /t:Compile;_CopyWebApplication  /p:Configuration=Release;WebProjectOutputDir=%BUILD_OUTDIR%;OutputPath=%BUILD_OUTDIR%\\bin"
                   echo "构建完成 => %BUILD_OUTDIR%" 
                   echo "开始打包程序"
                   bat "cd /d %BUILD_OUTDIR% && zip -9 -r ${BUILD_NUMBER}.zip ./ && mv ${BUILD_NUMBER}.zip ../ && cd ../ && rd /s/q ${BUILD_NUMBER}"
                   echo "打包完成 => ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                }
                
         }         
         stage('发布至测试'){
                steps{
                     node("$TEST_0_NODE") {
                         echo '下载程序'
                         bat "IF NOT EXIST \"${WORKSPACE}/download\"  MD \"${WORKSPACE}/download\" "
                         bat "curl -o download/${BUILD_NUMBER}.zip ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                         echo '解压源程序'
                         bat "unzip -o download/${BUILD_NUMBER}.zip -d %TEST_0_DEPLOYDIR% "
                    }
                }
         }   
         
         stage('检测测试环境运行状态'){
                 steps{
                    bat "${JENKINS_TOOL}/test.bat %TEST_URL% "
                 }
         } 
    
         //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 Begin-----------------------------
    	 
         stage('是否发布至正式'){
                steps{
                     timeout(time: 1, unit: 'DAYS') {
                     input message: '是否发布至正式?', ok: '发布'
                    }
                }
         }
         
         stage('发布至正式'){
                steps{
                     node("$PROD_1_NODE") {
                         echo '下载程序'
                         bat "IF NOT EXIST \"${WORKSPACE}/backup\"  MD \"${WORKSPACE}/backup\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/temp\"  MD \"${WORKSPACE}/temp\" "
                         bat "IF NOT EXIST \"${WORKSPACE}/download\"  MD \"${WORKSPACE}/download\" "
                         bat "curl -o download/${BUILD_NUMBER}.zip ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip"
                         echo '备份源程序'
                         bat "cd %PROD_1_DEPLOYDIR% && zip -r \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" ./"
                         echo '解压源程序'
                         bat "unzip -o download/${BUILD_NUMBER}.zip -d \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                         bat "\"${WORKSPACE}/../../deploy.bat\" ${WORKSPACE}/temp/${BUILD_NUMBER} %PROD_1_DEPLOYDIR%"
                    }
                }
                post {
                    always {
                        node("$PROD_1_NODE") {
                            echo '清理文件'
                            bat "rd /s /q \"${WORKSPACE}/temp/${BUILD_NUMBER}\" "
                        }
                    }
                 }
         }
         
         stage('检测生产环境运行状态'){
                steps{
                     bat "${JENKINS_TOOL}/test.bat %PROD_1_URL% "
                }
                post {
                    failure { 
                        node("$PROD_1_NODE"){
                                echo '发布失败,回滚该站点'
                                bat "rd /s /q %PROD_1_DEPLOYDIR% "
                                bat "unzip -o \"${WORKSPACE}/backup/${BUILD_NUMBER}.zip\" -d %PROD_1_DEPLOYDIR% "
                        }
                    }
                }
         }
    	 
        //-----------------------------如果要多机发布,请从此处开始拷贝,并替换PROD_X_XX 参数 END-----------------------------
     }
}

测试站点

#!/bin/sh

http_url=${1}

http_status=$(curl -Li $http_url | grep -oP "HTTP/\d\.\d 200 OK" || cat /dev/null)

if [ "$http_status" ];then
	exit 0;
else
	exit 1
fi
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区