.gitlab-ci.yml
git bash
命令行中创建。
# .gitlab-ci.yml
stages:
- autotest
自动化测试:
image: centos:7
stage: autotest
variables:
{
BASE_URL: 'http://xxx:8000', # 测试平台后端接口ip
QUERY: '/api/fastrunner/gitlab-ci/',
TASK_IDS: '22,70', # 需要运行的任务,多个任务用逗号分隔;不传或者为空,则运行所有的任务
PROJECT: 7, # 测试平台中的项目id
FULL_URL: '$BASE_URL$QUERY',
START_JOB_USER: '$GITLAB_USER_NAME',
}
script:
- echo start to request test platform...
- echo $FULL_URL
- |
curl -X POST $FULL_URL -H "Content-Type: application/json" -d '{"project": "'"$PROJECT"'", "task_ids": "'"$TASK_IDS"'", "ci_job_id": "'"$CI_JOB_ID"'", "ci_job_url": "'"$CI_JOB_URL"'", "ci_pipeline_id": "'"$CI_PIPELINE_ID"'", "ci_pipeline_url": "'"$CI_PIPELINE_URL"'", "ci_project_id": "'"$CI_PROJECT_ID"'", "ci_project_name": "'"$CI_PROJECT_NAME"'", "ci_project_namespace": "'"$CI_PROJECT_NAMESPACE"'", "start_job_user": "'"$START_JOB_USER"'"}' > report.xml;
- cat report.xml
- e=`cat report.xml|grep -Po "(?<=<errors>).*(?=</errors>)"`; echo errors count $e
- f=`cat report.xml|grep -Po "(?<=<failures>).*(?=</failures>)"`; echo failures count $f
- echo run test finish...
- if [[ $e -eq 0 && $f -eq 0 ]]; then exit 0; else exit 1; fi
after_script:
- echo $CI_JOB_ID $CI_JOB_STATUS
- curl -X GET "${FULL_URL}?ci_job_id=${CI_JOB_ID}" > result.txt
- cat result.txt
artifacts:
when: always
reports:
junit: report.xml
修改两个变量:
TASK_IDS
,需要运行的任务,多个任务用逗号分隔;不传或者为空,则运行所有的任务(任务状态需要是绿色的)PROJECT
,测试平台中的项目 id
中文名的作用: