Run Jenkins Job in a container
Solution 1
Of course, the answer is Yes, this is possible.
Given the broad type of question, I can only give pointers.
jenkins-pipeline offers a nice way to describe your pipelines as code. The docker plugin also integrates with that, so that you can run your jobs within a container, e.g.
// select a slave based on the label 'docker'
node('docker') {
stage "Run in container (e.g. the php-7)"
docker.image('php:7').inside {
// run your command
sh "phpunit"
}
}
There are couple of resources out there regarding jenkins-pipelinedocker that will get you started.
Solution 2
I found the plugin I was looking for.
https://plugins.jenkins.io/docker-custom-build-environment/
This will do what I want. It will allow me to run my jobs in a container. So far, it is working well.
Jon
Updated on August 01, 2022Comments
-
Jon almost 2 years
I have several Jenkins jobs and several Jenkins slave nodes (physical machines). These slaves are all running docker 1.12.1. I would like for any of these jobs to run on any of these slaves. Since these jobs have different environment requirements, I thought that I could create docker images for each of the different environments and then "within" the job, specify which container the job would run in.
Is this possible? i.e. to specify within these jobs a specific docker container that I would like these jobs to run in? At the end of the job, the containers would be destroyed and only the artifacts and reports would remain.
There are several docker plugins that exist in Jenkins but I have yet found one that does exactly what I want.
-
Bikal Basnet almost 7 yearsHow do you test in cases where multiple docker containers are needed? For eg. to perform a phpunit with database.
-
StephenKing almost 7 yearsPlease ask this as a separate question, not as a comment.