Hi everyone, I’m working in a startup and now we’ve decided to use Jenkins as tool for CI/CD because in our opinion it was the best choice.
We’re using Firebase services as backend and we’ve written our Unit tests using mocha.
I wrote the Jenkinsfile for the pipeline of our backend but I’m having a lot of difficulties while working with Firebase emulators.
My idea is the following: start the emulator in Jenkins and then in a stage after that one I run the npm test to test my endpoints.
This should be easy but when I start the emulators it starts correctly buy then it idles forever and I can’t go on with my tests.
So as a workaround I’m using parallel stages, one of the stages starts the emulator and the other one tests it after 5 minutes (5 minutes because the emulator takes a lot of time to start).
I need to test it of course but I was wondering if there’s a better way to approach this problem. How would you do this?
This is my Jenkinsfile
pipeline {
agent any
tools {
nodejs '19.4.0'
}
environment {
API_KEY_OPEN_DOTA = credentials('API_KEY_OPEN_DOTA')
FORTNITE_API_KEY = credentials('FORTNITE_API_KEY')
CLIENT_ID = credentials('CLIENT_ID')
STORM_TOKEN = credentials('STORM_TOKEN')
STRIPE_KEY = credentials('STRIPE_KEY')
FIREBASE_LOGIN_TOKEN = credentials('FIREBASE_LOGIN_TOKEN')
}
stages {
stage('setup') {
steps {
sh 'echo API_KEY_OPEN_DOTA=\"$API_KEY_OPEN_DOTA\" >> .env'
sh 'echo FORTNITE_API_KEY=\"$FORTNITE_API_KEY\" >> .env'
sh 'echo CLIENT_ID=\"$CLIENT_ID\" >> .env'
sh 'echo STORM_TOKEN=\"$STORM_TOKEN\" >> .env'
}
}
stage('installing npm packages') {
steps {
sh 'npm install'
sh 'cd functions && npm install'
sh 'npm install -g firebase-tools'
}
}
stage('jenkins') {
when {
branch 'jenkins'
}
parallel{
stage('starting emulators') {
steps {
sh 'firebase emulators:start --project myProjectName-64ea9'
}
}
stage('running tests on emulator') {
steps {
sleep(time: 5, unit: 'MINUTES')
sh 'npm run testUnix ./tests/endPoints/auth.test.ts'
}
}
}
}
}
}