jenkins+newman+postman+git(手动部署和docker部署)

手动部署

  1. 在jenkins服务器上安装nodejs,npm,newman,newman-reporter-htmlextra
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install npm
npm install -g newman 
npm install -g newman-reporter-htmlextra

检查命令

node -v   //v14.15.0
npm -v    //6.14.8
newman -v  //5.2.1
  1. 新建gitlab项目,将多个项目的postman的collection.json和environment.json上传。项目目录为postman/API_TEST_FILE
  2. 在jenkins服务器上添加插件: NodeJS Plugin
  3. 在jenkins添加流水线项目(此处文件路径要写完整)
def projectName = ''
pipeline {
    agent any
    
    triggers{
		xxx
	}
    
    stages {
    
        //获取触发项目信息
        stage ('checkBuilder') {
            steps {
                script {
                    def log =  currentBuild.buildCauses
                    def out = "${log}".tokenize('''"''')
                    projectName = "${out[1]}"
                    echo "{$projectName}"
                }
            }
        }
        
         stage('checkout') {
            steps {
                checkout([
                    $class: 'GitSCM',
                    branches: [[name: '*/master']],
                    userRemoteConfigs:[[
                        url: 'git@github.com:helpapa/postman.git',
                        credentialsId: 'helpapaSsh'
                    ]]
                ])
            }
        }
        
         stage ('at'){
            when {
                equals(expected: "at_pipeline", actual: "${projectName}")
            }
            steps {
                sleep 60
                script{
                sh 'newman run /home/ubuntu/.jenkins/workspace/postman/API_TEST_FILE/at_collection.json -e /home/ubuntu/.jenkins/workspace/postman/API_TEST_FILE/at_environment.json -r htmlextra --reporter-html-export /home/ubuntu/.jenkins/workspace/postman'
                }
            }
        }
        
        stage ('demo'){
            when {
                equals(expected: "demo", actual: "${projectName}")
            }
            steps {
                echo "demo postman run"
            }
        }
    }
}


  1. 构建成功后,在构建历史的workspace/newman处查看报告,如果报告没有css,则在Manage Jenkins-Script Console处运行代码System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
    相关资料资料资料2

docker部署

  1. 拉取htmlextra镜像,此镜像使用postman/newman:alpine为基础镜像
    docker pull dannydainton/htmlextra
  2. 运行代码:docker run --rm -t -v /workDir:/etc/newman dannydainton/htmlextra run at_collection.json -e at_environment.json -r htmlextra (workDir为存储json文件的路径,测试报告在/workDir/newman处)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值