jenkins下载gitlab自动化用例并每日批跑

1.安装Jenkins

---待补充

2.安装用例执行节点(虚拟机)

用例执行的虚拟机,需要安装python环境与依赖包(自动化脚本依赖包),需要申请外网权限(安装python依赖需要外网)。执行机需要挂靠到jenkins的某节点上

3.window虚机,报告存放地址

安装tamcat服务,Jenkins生成的报告会通过pipeline脚本上传到此windows上存放,然后外网可以通过访问tamcat的地址去访问对应的报告

4.Jenkins构建项目

首先需要新建节点(执行节点),用于pipeline执行绑定的机器

其次要新建credit id,用于Jenkins和gitlab认证,达到下载项目代码的目的

最后可以开始构建项目:

1. 配置一个Jenkins自动化项目流程

在Jenkins项目地址  上【New Item】个Pipline脚本项目,参照之前项目配置,主要填写pipline_script(具体运行步骤)jenkins下载gitlab自动化用例并每日批跑_第1张图片 pipline_script: 

jenkins下载gitlab自动化用例并每日批跑_第2张图片

 具体内容:

timeout(time: 4, unit: 'HOURS'){   
    node('APIautoTest'){
        def project = 'GKP1.5'
        def name = '知识智能平台V1.5'
        def exec_file = 'suite_by_dir_allRelease'
        def exec_env = ""
        def mail_to = '[email protected]'
        def ftp_address = '10.202.62.98'
        def ftp_port = '21'
        def ftp_tomcat_port = '8080'
        
       environment {
            LC_ALL = 'en_US.UTF-8'
            LANG    = 'en_US.UTF-8'
            LANGUAGE = 'en_US.UTF-8'
            PYTHONIOENCODING = "en_US.UTF-8"
        }
       stage("check out"){
            retry(3){
                git  credentialsId: '9801fa28-e345-47ee-86da-6738ed044013', url: '[email protected]:research/datascience-testing-engineers/GKP-API-automation.git',branch:"GKP_V1.5_server"
            }
        }
        stage("prepare"){
            '''
			sh "pip install urllib3==1.26.5"
			sh "pip install null"
				
				pip install null
                pip install pyyaml
                pip install mako
                pip install psycopg2-binary
                pip install ddt
                pip install py2neo
                '''
        }
        stage("test"){
    		sh "cd test_suite \n LC_CTYPE=zh_CN.UTF-8  python3 ${exec_file}.py -c jenkins"
        }
        stage("post"){
            allure includeProperties: false, jdk: '', report: "report/jenkins-html", results: [[path: "report/xml"]] 
        }
        stage("upload to ftp"){
            params = "-a ${ftp_address}:${ftp_port} -p ${project} -n ${BUILD_NUMBER}"
            if ("${exec_env}" != ""){  
                params = params + " -e ${exec_env}"
            }
            sh "cd common \n LC_CTYPE=zh_CN.UTF-8  python3 CommonFtp.py ${params}"
        }
        stage("send email"){
            dataObject = readJSON file: "report/jenkins-html/widgets/summary.json"
            failed = "${dataObject.statistic.failed}"
            broken = "${dataObject.statistic.broken}"
            skipped = "${dataObject.statistic.skipped}"
            passed = "${dataObject.statistic.passed}"
            total = "${dataObject.statistic.total}"
            if (total == '0'){
                status = "没有用例运行"
            }
            else if (total == passed){
                status = "运行成功"
            }
            else{
                status = "运行出错"
            }
            
            if ("exec_env" != ""){
                report_address = "http://${ftp_address}:${ftp_tomcat_port}/${project}/${exec_env}/${env.BUILD_NUMBER}/index.html"
            }
            else{
                report_address = "http://${ftp_address}:${ftp_tomcat_port}/${project}/${env.BUILD_NUMBER}/index.html"
            }
            
            
            emailext body: """
            

构建地址:${env.BUILD_URL} (需要先登录jenkins且有项目权限)

构建日志地址:${env.BUILD_URL}console (需要先登录jenkins且有项目权限)

测试报告:${report_address}

概要结果:

  • 总用例数:${total}
  • 成功数:${passed}
  • 失败数:${failed}
  • 错误数:${broken}
  • 跳过数:${skipped}

""", subject: "【${name}】高频用例测试报告 - ${env.BUILD_NUMBER} -${status}", to: "${mail_to}" } } }

2. 将 Pipline项目挂着定时控制器上 Jenkins定时器

jenkins下载gitlab自动化用例并每日批跑_第3张图片

3. 调试Pipline项目

jenkins下载gitlab自动化用例并每日批跑_第4张图片

 

 

你可能感兴趣的:(jenkins,gitlab,自动化)