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
- docker installed
- allure plugin installed
Configurations
-
Create a new pipeline job on Jenkins
-
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.
-
Create Dockerfile, run-tests.sh to build the image. Can refer to this https://github.com/PeterNgTr/codeceptjs-rest-demo/tree/master/docker
-
Create Jenkinsfile, run-tests.sh to use for Jenkins pipeline. Can refer to this https://github.com/PeterNgTr/codeceptjs-rest-demo/tree/master/jenkins
- In Jenkinsfile, this will define the allure configurations -> https://github.com/PeterNgTr/codeceptjs-rest-demo/blob/master/jenkins/Jenkinsfile#L23
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']]
}
}
}
- In the script, it will run the docker image that we prepare in step #3, and cause the tests are run in the container, so we need to map the report volume of host (Jenkins) to container that executed tests. As it is defined here -> https://github.com/PeterNgTr/codeceptjs-rest-demo/blob/master/jenkins/run-tests.sh#L9
#!/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}
- Trigger the build and enjoy the coffee