pipeline腳本:
pipeline {
agent {
node {
label 'maven'
}
}
stages {
stage('代碼檢出') {
steps {
echo 'checkout strart ...'
echo "分支tag爲:${env.git_tag}"
script {
checkout([$class: 'GitSCM', branches: [[name: "origin/master"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "xxxx", url: "xxxxxxxxxxxxxxxxxxxxxxx"]]])
// 當前工作空間授權
sh "chmod -R 777 ${env.WORKSPACE}"
}
}
}
stage('接口測試') {
steps {
container ('maven') {
sh """
export http_proxy='http://xxx'
export https_proxy='http://xxxx'
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar -zxvf Python-3.6.0.tgz
mkdir /usr/local/python3
cd Python-3.6.0
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
"""
dir("${env.WORKSPACE}/Interface/Maxbase_2.0"){
sh " cp ./tools/HTMLTestRunner.py /usr/local/python3/lib/python3.6"
sh " pip3 install -r ./requirement.txt -proxy='http://xxxxxxxxxx'"
sh "sed -i \"s/xxx/xxx/g\" ./framework/global_value.py"
sh " python3 TestRunner.py"
}
}
}
}
}
}
遇到問題:
1.由於公司用的內網,所以需要配置全局代理來wget,pip代理下載依賴插件
2.由於linux下載的python3.0的包裏面沒有HTMLTestRunner.py文件,導致加載的時候找不到HTMLTestRunner模塊報錯,所以需要官網下載高版本的HTMLTestRunner.py文件,並導入安裝目錄下的lib包裏面