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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With