自动化测试实战:0基础→自动化测试框架→企业级自动化持续集成_持续集成测试框架

    - mountPath: "/var/run/docker.sock"
      name: "dockersock"
      readOnly: false
- image: "registry.cn-chengdu.aliyuncs.com/qzcsbj6/maven"
  imagePullPolicy: "IfNotPresent"
  name: "maven"
  tty: true
  command:
    - "cat"
  env:
    - name: "LANGUAGE"
      value: "en_US:en"
    - name: "LANG"
      value: "en_US.UTF-8"
  volumeMounts:
    - mountPath: "/etc/localtime"
      name: "localtime"
    - mountPath: "/root/.m2/"
      name: "m2dir"
      readOnly: false
- image: "registry.cn-chengdu.aliyuncs.com/allure-commandline"
  imagePullPolicy: "IfNotPresent"
  name: "allure"
  tty: true
  command:
    - "cat"
  env:
    - name: "LANGUAGE"
      value: "en_US:en"
    - name: "LANG"
      value: "en_US.UTF-8"
  volumeMounts:
    - mountPath: "/etc/localtime"
      name: "localtime"
      readOnly: false

restartPolicy: “Never”
volumes:
- name: “dockersock”
hostPath:
path: “/var/run/docker.sock”
- name: “localtime”
hostPath:
path: “/usr/share/zoneinfo/Asia/Shanghai”
- name: “m2dir”
hostPath:
path: “/opt/m2”
‘’’
}
}


pull project code



stage(‘pull project code’) {
parallel {
stage(‘ui build’) {
when {
expression {
env.gitlabBranch == null
}
}
steps {
sh “”"
echo ‘=================开始拉取项目代码’
“”"

    git(url: 'git@192.168.117.180:qzcsbj/gift.git', branch: "${BRANCH}", credentialsId: 'qzcsbj_gitlab')
    script {
        COMMIT_ID = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
        TAG = BUILD_TAG + '-' + COMMIT_ID
        println "Current branch is ${BRANCH}, Commit ID is ${COMMIT_ID}, Image TAG is ${TAG}"
    }           
  }
  post {
    failure {
      dingtalk (
        robot:'dd01',
        type:'MARKDOWN',
        atAll: true,
        title: "notice: 拉取项目代码失败",
        text: ["#### '${JOB_NAME}'项目代码拉取失败\n - 构建:第'${BUILD_NUMBER}'次\n - 状态:'${currentBuild.result}'\n - [查看本次构建详情](${BUILD_URL})"]
      )
    }
  }
}
stage('trigger build') {
  steps {
    sh """
      echo "待更新。。。"
    """
  }
}

}
}


mvn package



stage(‘mvn package’) {
steps {
container(name: ‘maven’) {
sh “”"
echo ‘=================mvn开始打包’
mvn clean package -Dmaven.test.skip=true
echo ‘=================mvn打包完成’
“”"
}
}
post {
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: mvn package失败”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 27: …项目mvn package失败\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL})”]
)
}
}
}


build and push image



stage(‘build and push image’) {
environment {
HARBOR_USER = credentials(‘qzcsbj_harbor’)
}
steps {
container(name: ‘docker’) {
sh “”"
echo ‘=================开始构建镜像’
docker build -t H A R B O R A D D R E S S / {HARBOR_ADDRESS}/ HARBORADDRESS/{REGISTRY_DIR}/ I M A G E N A M E : {IMAGE_NAME}: IMAGENAME:{TAG} .
docker login -u ${HARBOR_USER_USR} -p ${HARBOR_USER_PSW} ${HARBOR_ADDRESS}
docker push H A R B O R A D D R E S S / {HARBOR_ADDRESS}/ HARBORADDRESS/{REGISTRY_DIR}/ I M A G E N A M E : {IMAGE_NAME}: IMAGENAME:{TAG}
echo ‘=================镜像推送完成’
“”"
}
}
post {
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 构建或者推送镜像失败”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 24: …E}'项目构建或者推送镜像失败\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL})”]
)
}
}
}


deploy to k8s



stage(‘deploy to k8s’) {
environment {
MY_KUBECONFIG = credentials(‘qzcsbj_k8s’)
}
steps {
container(name: ‘kubectl’){
sh “”"
echo ‘=================开始部署到k8s’
/usr/local/bin/kubectl --kubeconfig M Y K U B E C O N F I G s e t i m a g e d e p l o y − l a p p = MY_KUBECONFIG set image deploy -l app= MYKUBECONFIGsetimagedeploylapp={IMAGE_NAME} I M A G E N A M E = {IMAGE_NAME}= IMAGENAME={HARBOR_ADDRESS}/ R E G I S T R Y D I R / {REGISTRY_DIR}/ REGISTRYDIR/{IMAGE_NAME}😒{TAG} -n KaTeX parse error: Expected 'EOF', got '}' at position 66: … """ }̲ } post { …{JOB_NAME}‘项目自动化部署到k8s完成\n - 构建:第’KaTeX parse error: Undefined control sequence: \n at position 17: …BUILD_NUMBER}'次\̲n̲ ̲- 状态:'{currentBuild.result}'\n - 查看本次构建详情"]
)
}
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化部署到k8s失败”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 25: …}'项目自动化部署到k8s失败\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL})”]
)
}
}
}


pull autotest code



stage(“pull autotest code”){
steps{
sh “”"
echo ‘=================开始拉取自动化测试代码’
“”"
git(
credentialsId: ‘qzcsbj_gitlab’,
url: ‘git@192.168.117.180:root/apiautotest.git’
)
}
post {
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 拉取自动化测试代码失败”,
text: [“#### 拉取自动化测试代码失败\n - 构建:第’KaTeX parse error: Undefined control sequence: \n at position 17: …BUILD_NUMBER}'次\̲n̲ ̲- 状态:'{currentBuild.result}'\n - 查看本次构建详情”]
)
}
}
}


run autotest



stage(“run autotest”){
steps{
sh “”"
mvn clean test -Dsurefire.suiteXmlFiles=testngXML/testng.xml
“”"
}
post {
success {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化测试完成”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 21: …NAME}'项目自动化测试完成\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL}console)”]
)
}
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化测试运行出错”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 23: …ME}'项目自动化测试运行出错\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL})”]
)
}
}
}


allure report



stage(“allure report”){
steps{
sh “”"
echo ‘=================开始生成测试报告’
“”"
allure(
includeProperties: false,
jdk: ‘’,
results: [[path: ‘target/allure-results’]]
)
}
post {
success {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化测试报告已生成,全部通过”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 29: …自动化测试报告已生成,全部通过\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次测试报告]({BUILD_URL}allure)”]
)
}
unstable {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化测试报告已生成,有未通过的”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 30: …动化测试报告已生成,有未通过的\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次测试报告]({BUILD_URL}allure)”]
)
}
failure {
dingtalk (
robot:‘dd01’,
type:‘MARKDOWN’,
atAll: true,
title: “notice: 自动化测试报告生成出错”,
text: [“#### 'KaTeX parse error: Undefined control sequence: \n at position 25: …}'项目自动化测试报告生成出错\̲n̲ ̲- 构建:第'{BUILD_NUMBER}‘次\n - 状态:’KaTeX parse error: Undefined control sequence: \n at position 23: …tBuild.result}'\̲n̲ ̲- [查看本次构建详情]({BUILD_URL})”]
)
}
}
}


### 08 构建及效果展示


pipeline脚本可以放在流水线项目的脚本框中


![图片](https://img-blog.csdnimg.cn/9e0805c0e61e44b1932624de6686791a.png)


也可以放gitlab上,选择SCM


![在这里插入图片描述](https://img-blog.csdnimg.cn/2b0906a15a32458288e2921362211882.png)


![图片](https://img-blog.csdnimg.cn/2ad9ee17eb454dea82b499b2f267320c.png)


![图片](https://img-blog.csdnimg.cn/2c9b3a26cff44a958af2215454c5cd41.png)


pipeline脚本放到Jenkinsfile中,Jenkinsfile在gift项目master分支下


![在这里插入图片描述](https://img-blog.csdnimg.cn/0201101dafa74a4b901985357b2c6b08.png)


第一次构建,点击“Build Now”,会失败,因为我们使用了参数化构建,这次构建获取不到参数值


![在这里插入图片描述](https://img-blog.csdnimg.cn/e2d4960c359f46b3bc5a9732ee54da22.png)


刷新页面,就可以看到参数化构建了,就可以选择要构建的分支


![在这里插入图片描述](https://img-blog.csdnimg.cn/b1c99b8b68f742ce9be46cc333e4f724.png)


部署到k8s的通知


![在这里插入图片描述](https://img-blog.csdnimg.cn/b1008eb685004c12a1c620c8767c1925.png)


消息


![在这里插入图片描述](https://img-blog.csdnimg.cn/9cd682d8fe994488b92db208916e8338.png)


运行自动化测试的通知


![在这里插入图片描述](https://img-blog.csdnimg.cn/9f4f53d55cdd44a4b279c519c1211c55.png)


消息


![在这里插入图片描述](https://img-blog.csdnimg.cn/10897ef4b351420e865f623a9f4d3404.png)


生成allure测试报告的通知


![在这里插入图片描述](https://img-blog.csdnimg.cn/6af174d0ae9a4352a1d9861bab09442f.png)


消息


![在这里插入图片描述](https://img-blog.csdnimg.cn/e4a51c10dfac4c8b9ee1962f711156b7.png)


测试报告的通知可以优化,直接链接到allure测试报告


![在这里插入图片描述](https://img-blog.csdnimg.cn/fa3eee1b6686499f91daafebc6086219.png)


测试报告


![在这里插入图片描述](https://img-blog.csdnimg.cn/f251b9760afe46418b2f8cecdf69e2c2.png)


![图片](https://img-blog.csdnimg.cn/fe560a3017cd4189b6208cea2c24239b.png)


声明:封面或正文部分图片来源于网络,如有侵权,请联系删除。



> 
> **现在我邀请你进入我们的软件测试学习交流群:**【**`746506216`**】,备注“入群”, 大家可以一起探讨交流软件测试,共同学习软件测试技术、面试等软件测试方方面面,还会有免费直播课,收获更多测试技巧,**`我们一起进阶Python自动化测试/测试开发,走向高薪之路。`**
> 
> 
> 


**喜欢软件测试的小伙伴们,如果我的博客对你有帮助、如果你喜欢我的博客内容,请 “点赞” “评论” “收藏” 一 键三连哦!**



> 
> ![在这里插入图片描述](https://img-blog.csdnimg.cn/5d962e6050ba484bbfb29735de4c08d4.png#pic_center)
> 
> 
> 


![img](https://img-blog.csdnimg.cn/img_convert/f61a6f39a8a31fdf629f78137e617d2d.png)
![img](https://img-blog.csdnimg.cn/img_convert/8a6a5babf96a0db9c2d70e30ab6f4b88.png)
![img](https://img-blog.csdnimg.cn/img_convert/d6c65a815bf185657c20188b666a0c8b.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**

试技巧,**`我们一起进阶Python自动化测试/测试开发,走向高薪之路。`**
> 
> 
> 


**喜欢软件测试的小伙伴们,如果我的博客对你有帮助、如果你喜欢我的博客内容,请 “点赞” “评论” “收藏” 一 键三连哦!**



> 
> ![在这里插入图片描述](https://img-blog.csdnimg.cn/5d962e6050ba484bbfb29735de4c08d4.png#pic_center)
> 
> 
> 


[外链图片转存中...(img-BpG4S4F5-1719277676183)]
[外链图片转存中...(img-PvoKtImt-1719277676184)]
[外链图片转存中...(img-b4VsFoEk-1719277676184)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**

  • 15
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值