I am configuring a Jenkins controller to start agents with kubernetes.
When a slave starts its pipeline I need him to have a maven settings.xml
read (or copied) from the controller.
With kubernetes plugin I haven't found a way for that.
Maybe Jenkins Pipeline: Basic Steps can help you out. They offer a stash/unstash step. Meaning you stash the settings.xml
on the master node and unstash it on your slave that runs the build. I think currently stash/unstash only support sub-directories of the current pipeline workspace, but you could work around it by copying the settings.xml
into the current workspace before stashing. The whole thing might look something like that:
stage('Build') {
node('master') {
sh 'cp /path/to/master-node-settings-xml .'
stash includes: 'settings.xml', name: 'settingsXml'
}
node('slave') {
unstash 'settingsXml'
sh 'mv settings.xml /path/to/slave-node-settings-xml'
# Start your build here now ..
}
}
Another option would be to pre-bake the settings.xml
into the docker image which you are using to spin up the slave in Kubernetes. Of course this would not be an optimal solution, if your settings.xml
changes dynamically or contains any kind of sensitive data (as one should avoid putting sensitive information inside a docker image if possible).