I've recently been setting up my own little CI/CD setup using Docker and Jenkins. I've installed the new Blue Ocean plugin for Jenkins and set up a pipeline that: Pulls from Git -> Runs tests -> Builds. Which works perfectly.
However, I've not been able to find out how to create an appropriate deploy/publish step in the pipeline. After the build, I want the Jenkins container to SSH onto my VPS that is running all the Docker containers, pull and then re-build that specific container (using Docker Compose).
I noticed within Blue Ocean there is the option to input a bash script that'll run after test/build - is this what I should be using?
I have been looking at using the Publish over SSH plugin for Jenkins but I have not been able to find whether this plugin works with Blue Ocean, nor have I been able to find out how to create ssh keys for the Jenkins container to be used.
I would greatly appreciate any insight/recommendations into how I should publish/build the updated containers.
A simple sh 'ssh...'
step should be enough to call a script on your VPS, which would (the script) handle all docker operations.
If your private ssh key is protected with a passphrase, you might want to wrap that call in an agent with the pipeline steps "ssh-agent":
node {
sshagent (credentials: ['deploy-dev']) {
sh 'ssh -o StrictHostKeyChecking=no -l cloudbees 192.168.1.106 uname -a'
}
}
As pmr comments, the JENKINS SSH Credentials Plugin can be used to stored the ssh private key.
You can also read the recent article "SSH Credentials Management with Jenkins".