I would like to include php unit testing with laravel in one of the jenkins steps. I was wanting to know what is best practise.
My Jenkins is hosted on a EC2 instance with php 7.3 installed.
I have many different branches from bitbucket that i would need to perform testing on. Some of them use different versions of php.
Composer install fails on some projects because of the PHP requirement.
I would like to do testing on commits? maybe to a candidate branch on feature merges? im not sure of best approach to do testing in general.
The project i am currently bust with is a docker image with php 8. Do i spin up this image with jenkins and perform testing? Do i build a new image the whole time on a candidate commit and do testing where it is hosted?
Hope this makes sense to a devops in what im trying to ask.
I don’t want you to feel ignored, but I also think this deserves a longer answer which I’ll try to do in the morning if nobody else replies.
Caveat: I use github with its plugins and don’t know the bitbucket terms.
This sounds very much like you want multi branch pipelines. Which allows you to have one job that handles different branches, and cleanup and merges without having to configure each one. You can apply regexes and stuff to filter out what you don’t want
This is kinda all over the place, but I think your saying you have different PHP requirements on each branch. Does your jenkins have access do docker? then this is easy. If not, assuming linux, something like asdf works really well. If no docker and windows, then I’m out of my element.
Yes, i have docker running in the EC2 instance alongside Jenkins so Jenkins has access. I have just installed the Docker plugin and the Docker pipeline project.
So you’re saying that i can just do this if i have a docker file? agent { dockerfile true }
I am currently doing this which means i need an existing image to be created. Would be great if i can just use my bucket Dockerfile and then Jenkins can spin it up to do tests…
stages {
stage('Building') {
steps {
echo 'build the new nginx and php images'
}
}
stage('Testing') {
agent {
docker {
image '<image url: latest>'
registryUrl '<url>'
registryCredentialsId '<login details>'
// args '-u root:sudo'
}
}
steps {
echo 'Running PHP 8.1 tests inside the container...'
sh 'php -v'
// echo 'Installing project composer dependencies...'
sh 'cd ${WORKSPACE} && composer install --no-progress'
echo 'Running PHPUnit tests...'
sh 'php ${WORKSPACE}/artisan test --coverage-html ${WORKSPACE}/report/clover --coverage-clover ${WORKSPACE}/report/clover.xml --log-junit ${WORKSPACE}/report/junit.xml'
sh 'chmod -R a+w $PWD && chmod -R a+w ${WORKSPACE}'
junit 'report/*.xml'
}