Linux 环境下载allure-commandline环境相关问题、配置环境变量问题
问题描述:
jenkins安装在Linux服务器
Jenkins下执行pipeline脚本生成allure报告,报错:
java.io.IOException: Can't find allure commandline <null>
完整报错信息:
java.io.IOException: Can't find allure commandline <null> at ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation$2.call(AllureCommandlineInstallation.java:63) at ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation$2.call(AllureCommandlineInstallation.java:58) at hudson.remoting.LocalChannel.call(LocalChannel.java:45) at ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation.getMajorVersion(AllureCommandlineInstallation.java:58) at ru.yandex.qatools.allure.jenkins.ReportBuilder.build(ReportBuilder.java:52) at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.generateReport(AllureReportPublisher.java:312) at ru.yandex.qatools.allure.jenkins.AllureReportPublisher.perform(AllureReportPublisher.java:231) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
问题分析:
既然缺少allure commandline,那就需要安装一个,
要配置allure-commandline ,官网上查一波,执行如下安装命令一直报错
$ sudo apt-add-repository ppa:yandex-qatools/allure-framework $ sudo apt-get update $ sudo apt-get install allure-commandline
查了好久也无果,因此尝试了其他办法,在这里记录一下:
解决办法:
下载allure-commandline的zip包到本地windows机器上,然后再配置临时环境变量。
1.下载,下载allure-commandline 的zip包到本地windows机器上,下载地址:
https://registry.npmjs.org/allure-commandline/-/allure-commandline-2.13.0.tgz
2.上传,将下载的zip包上传到Linux机器上
使用rz命令j将下载的 allure-commandline上传到Linux服务器上,
(1)需要注意的是,要记住当前的目录
(2)allure环境依赖jdk1.8以上版本,如果小于1.8版本,也可以在pipeline脚本内引入临时环境变量
(3)Linux临时环境变量,定义可以参考:https://www.cnblogs.com/haore147/p/3633116.html
3.解压,unzip allure-comandline-(你上传的allure-commandline文件名)
4.再pipeline脚本内设置临时allure环境变量,具体如下:
pipeline{ agent any environment{ allure_home = '/usr/home/ya/allure-commandline-2.13.0/dist/bin/' JAVA_HOME = '/usr/home/ya/openjdk-8' //因为allure要求jdk1.8以上,本地是1.7因此这里需要配置下jdk1.8 } stages{ stage(’deploy‘) steps{ echo '正在部署环境' } stage('Testing'){ steps{ echo ‘正在执行测试用例’ pipenv run pytest --alluredir=../results -s -v -p no:warnings } } } post{ always{ //设置allur和jdk环境变量 ,环境变量的设置在allure应该还有更好的方法,待研究。
sh''' export PATH="${JAVA_HOME}"/bin:$PATH export PATH="${allure_home}":$PATH java -version allure --version '''
script { allure includeProperties: false,jdk: '', report:'report',results:[[path:'results']] } }
这样问题就解决了!
如有不足之处,欢迎大家指正,共同学习进步~!
每天进步一小步,就会有个新高度~