Jenkins pipeline with pytest and allure

Use pipeline to better manage Jenkins job:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 pipeline {
agent {
label 'jenkins_master'
}

parameters {
string defaultValue: '/tests/', description: 'Set test suite', name: 'TestSuite', trim: true
choice choices: ['qa', 'dev', 'product'], description: 'Set test run env', name: 'Environment'
string defaultValue: '', description: 'Set tag to run', name: 'Tag', trim: true
string defaultValue: '2', description: 'Set rerun times when failed', name: 'Rerun', trim: true
string defaultValue: '1', description: 'Set multiple thread to run', name: 'Parallel', trim: true
}

stages {
stage('Get Automaiton Code') {
steps{
git credentialsId: 'xxxxxxx', url: 'https://xxx/api_automation.git'
}
}

stage('Run Automation') {
steps{
sh label: '', script: '''if [ ! $Tag ]; then

pytest -s -v ${WORKSPACE}${TestSuite} --reruns ${Rerun} -n ${Parallel} --alluredir=./report/json --clean-alluredir

else

pytest -s -v ${WORKSPACE}${TestSuite} -m ${Tag} --reruns ${Rerun} -n ${Parallel} --alluredir=./report/json --clean-alluredir

fi'''

}
}

}

post('Allure Report') {
always{
script{
allure includeProperties: false, jdk: '', report: 'report/html/', results: [[path: 'report/json']]
}
}
}
}
唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!