robot+jenkins

执行机镜像构建

基础镜像选择python3
需要作为ansible的执行机,所以需要安装ssh,python2
并且安装robotframework插件

FROM cargo-regression-a.caicloudprivatetest.com/library/python:3.6.5-alpine3.6
ADD compass/devops/requirements.txt /app/
RUN apk update && \
    apk add --no-cache openssh-server tzdata python && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
    ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
    ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
    ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key && \
    echo "root:admin" | chpasswd
WORKDIR /app
RUN pip3 install -r requirements.txt
CMD /usr/sbin/sshd -D

requirement

robotframework
robotframework-requests

jenkins配置

使用虚机安装jenkins和ansible
ansible的配置
hosts

[rfrun]
192.168.132.1  ansible_ssh_user=root  ansible_ssh_pass=admin   ansible_ssh_port=30787

playbook

- hosts: localhost
  tasks:
  - name: delete old result
    file: path=/var/lib/jenkins/workspace/robot/output.xml state=absent
  - name: delete old result
    file: path=/var/lib/jenkins/workspace/robot/report.html state=absent
  - name: delete old result
    file: path=/var/lib/jenkins/workspace/robot/log.html state=absent

- hosts: rfrun
  tasks:
  - name: copy test case
    copy: src=../compass/devops dest=/app
  - name: create result directory
    file: path=/app/result state=directory
  - name: exec-dcetest
    shell: /usr/local/bin/robot --outputdir  /app/result /app/devops/测试用例/API/API.txt
  - name: fetch result
    fetch: src=/app/result/output.xml dest=/var/lib/jenkins/workspace/robot/ flat=yes
  - name: fetch result
    fetch: src=/app/result/report.html dest=/var/lib/jenkins/workspace/robot/ flat=yes
  - name: fetch result
    fetch: src=/app/result/log.html dest=/var/lib/jenkins/workspace/robot/ flat=yes

jenkins设置
执行脚本

ansible-playbook -i jenkinsrobot/hosts jenkinsrobot/ansibleplay.yaml

你可能感兴趣的:(robot+jenkins)