cqlcorp/jenkins-swarm-agent is simple image that runs the jenkins swarm plugin jar file which connects to a given master using parameters
https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin
On the testing docker swarm
docker service create \
--mode=global \
--name jenkins-swarm-agent \
-e LABELS=docker-test \
--mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \
--mount "type=bind,source=/tmp/,target=/tmp/" \
cqlcorp/jenkins-swarm-agent
On the staging docker swarm
docker service create \
--mode=global \
--name jenkins-swarm-agent \
-e LABELS=docker-stage \
--mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \
--mount "type=bind,source=/tmp/,target=/tmp/" \
cqlcorp/jenkins-swarm-agent
On the production Docker swarm
docker service create \
--mode=global \
--name jenkins-swarm-agent \
-e LABELS=docker-prod \
--mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \
--mount "type=bind,source=/tmp/,target=/tmp/" \
cqlcorp/jenkins-swarm-agent
- mode=global when we add new nodes to the Docker cluster they will all connect to the jenkins master to serve as slaves
- mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" we mount the Docker socket so that we can use the Docker client inside a container to start new containers or services directly on the host. This is a better approach than Docker in Docker
- mount "type=bind,source=/tmp/,target=/tmp/" all containers can share files generated by the same Jenkins job
- LABELS=docker-test the jenkins slave label. This is used when you define where to run each pipeline step - the labels need to match the ones used in the Jenkinsfile - node("docker-test") , node("docker-stage") , node("docker-prod")
Required env variables:
-e JENKINS_URL=https://jenkins.example.com
-e JENKINS_SSL_FINGERPRINTS=SHA256FINGERPRINTS
-e JENKINS_USERNAME=AgentUsername
The password for the Jenkins username should be set as a secret named jenkins-agent-password
.
Supported env variables - if not set the defaults are used
-e LABELS="docker" - node labels
-e EXECUTORS="3" - number of executors
-e FSROOT="/tmp/jenkins" - data directory , jenkins need to have write access to - best to leave the defaults.
Credits
Initially cloned from vipconsult/jenkins-swarm-agent and updated to suit our needs.