LoginSignup
2
3

More than 5 years have passed since last update.

Jenkins PipelineでテストJobの実行 (Selenium)

Last updated at Posted at 2018-03-15

概要

Seleniumのテストコードを複数作成した場合、どうやってJenkinsで定期実行するかを調べたのでメモしておく。

ファイル構成

下記のようなファイルの構成で作成する。

ファイル一覧
├ groovy
│  ├ script
│  │ └ slack.groovy
│  └ Jenkinsfile
└ python
   ├ test001-hoge.py
   └ test002-fuga.py

実行環境

DockerのJenkins(公式)コンテナにpython3を追加したものを利用することにします。

Dockerfile
FROM jenkins
USER root

# system update
RUN apt-get update

# locale
RUN apt-get -y install locales && \
    localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8

# timezone (Asia/Tokyo)
ENV TZ JST-9

# etc
ENV TERM xterm

# add tools to work.
RUN apt-get install -y vim less

# python3 install
RUN apt-get install -y python3 python3-pip
RUN apt-get -f install
RUN apt-get install -y libnss3-tools libnss3 libnss3-dbg libnss3-dev
RUN apt-get install -y libgconf2-4 libxss1
RUN apt-get install -y fonts-liberation libappindicator1 xdg-utils

# selenium install
RUN pip3 install selenium

Slack通知メソッド作成

下記の投稿に作り方がありますのでそちらを参照ください。

Jenkinsfile作成

Jenkinsfile
#!/usr/bin/env groovy

pipeline {
    agent any
    environment {
        TEST_ENV='testing'
    }
    options {
        timeout(time: 1, unit: 'HOURS')
    }
    stages {
        stage('Seleniumテスト') {
            parallel {
                stage('シナリオ-001') {
                    steps {
                        script {
                            retry(5) {
                                sh "python3 ${pwd()}/python/test001-hoge.py"
                            }
                        }
                    }
                }
                stage('シナリオ-002') {
                    steps {
                        script {
                            retry(5) {
                                sh "python3 ${pwd()}/python/test002-fuga.py"
                            }
                        }
                    }
                }
            }
        }
    }
    post {
        success {
            echo 'All Test OK'
        }
        failure {
            script{
                slack = load "${pwd()}/groovy/script/slack.groovy"
                slack.post('danger', 'FAIL')
            }
        }
    }
}

参考サイト(pipeline plugin)

参考サイト(Multijob plugin)

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3