Online Training: Web test automation with CodeceptJS. Sign up now!

CodeceptJS - Jenkins Integration

Recently, I have chance to play around with setting up the smoke tests using Codeceptjs - Jenkins CI. Hence, that would be a good time to write down something for anyone that has troubles with Codeceptjs - Jenkins will have a reference.

I’m using this project in this setup: https://github.com/PeterNgTr/codeceptjs-rest-demo

Prerequisites

Configurations

  1. Create a new pipeline job on Jenkins

  2. Configure it as following

script path is like this jenkins/Jenkinsfile cause that the path of script in my repo, it could be different with yours.

  1. Create Dockerfile, run-tests.sh to build the image. Can refer to this https://github.com/PeterNgTr/codeceptjs-rest-demo/tree/master/docker

  2. Create Jenkinsfile, run-tests.sh to use for Jenkins pipeline. Can refer to this https://github.com/PeterNgTr/codeceptjs-rest-demo/tree/master/jenkins

node {

    def imageTag = "peterngtr/rest-demo:${env.BUILD_NUMBER}"
    def dockerHome = tool 'myDocker'

    stage("Initializing") {
        cleanWs();
        checkout scm;
        sh 'git reset --hard'
        env.PATH = "${dockerHome}/bin:${env.PATH}"
    }

    stage("Building Images") {
        sh "docker build -t ${imageTag} -f docker/Dockerfile ."
    }

    stage("Running Tests") {
        try {
            sh "jenkins/run-tests.sh ${env.BUILD_NUMBER}"
        }
        finally {
            sh "ls report/"
            allure includeProperties: false, jdk: '', results: [[path: 'report']]
        }
    }


}
#!/usr/bin/env bash

VERSION=${1:-latest}

echo "Pulling image ${VERSION}"
mkdir report

docker run --rm \
    -v "$(pwd)"/report/:/app/report/ \
    peterngtr/rest-demo:${VERSION}

status=$?

echo "Final status ${status}"
exit ${status}
  1. Trigger the build and enjoy the coffee :slight_smile:

2 Likes

Hi, this is great! I just have one question. Do you have a specific configuration for Allure? I’ve never been able to see the test trends like in the screenshot you shared

Hi @ufko, I didn’t setup anything else beside the defaults. But yeah, that trend looks cool!

It’s really cool :smiley: Thanks!