Jenkins-Test

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。Jenkins-Test,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

示例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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/160303.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!