pipeline建立自动化测试job

背景

最近读了一本书,讲CICD,从《敏捷测试》到pipeline实战演练

不得不得承认Jenkins bule ocean,界面风格十分nice,探索了pipeline中的测试步骤

 

前期-----

实话书里直接就是pipeline的测试步骤就是,main-->xxxxx testcase,所有框架都是这样的收集测试用例并运行。

而实际项目中,jenkins的linux节点服务器,被各个项目或者其他同事所共用,就像1间房子其他人也在住,怎么样隔离环境,其实就是容器化技术docker

所以Jenkins blue + pipline + docker....开始了,如下;

1、构建镜像   (包括了依赖环境、代码等)

2、实例出容器

3、容器运行命令行

4、生成报告

---------------------------------------

之前提及的docker做UI自动化是一致的,但是新建了依赖包、库之类的,构建镜像的依赖环境应该如何处理?只能重新升级、添加依赖。

将旧的的依赖镜像删除,重新通过pip install -r requirements生成新的镜像,进而有了如下的自动化的一步【推送镜像】,检查到requiremets就会做如下步骤

 

jenkinsfile 如下

pipeline {
agent {
label "master"
}
options {
buildDiscarder(logRotator(numToKeepStr: '15'))
disableConcurrentBuilds()
timestamps()
timeout(12)
}
parameters {
choice(name: 'test_env', choices: ['test','gray'],description: 'test 测试环境\ngray 灰度环境')
choice(name: 'marker', choices: ['all','smoke'],description: '选择用例')
booleanParam(name: 'build', defaultValue: false, description: '构建容器')

}

stages {

stage("推送镜像") {
when {
changeset "requirements.txt"
}

steps {
sh 'cat pwd.txt | docker login
sh 'docker build -t python:latest --rm --no-cache -f lib/Dockerfile .'
sh 'docker tag '
sh 'docker push'
sh 'docker rmi '
}
}

stage("构建自动化测试镜像"){

when{
anyOf {
changeset "testcase/**/*.py"
changeset "conf/config.ini"
equals expected: "${params.build}",
actual: 'True'
}
}
steps {
echo '开始构建'
sh '/usr/local/bin/docker-compose down'
sh '/usr/local/bin/docker-compose build --no-cache'
}
}

stage("容器执行用例") {

steps {
sh '/usr/local/bin/docker-compose up'
}
post('测试报告') {
always{
script{
allure includeProperties: false, jdk: '', report: 'report/allure_report', results: [[path: 'report/allure_result']]
}
}

}
}

stage("生成测试报告") {
steps{
sh 'echo 生成报告中'
}
post('测试报告') {
always{
}
}
}

}
}

 

posted @ 2021-11-10 11:33  半城风雨  阅读(368)  评论(0)    收藏  举报