Keep a few examples of Jenkins Pipelines. Mostly used for demo and training.
Look in each directory and find the Jenkinsfile with the example. See more details are in the Jenkinsfile comments.
You are more than welcome to contribute, share and ask.
These examples assume a simple setup of a single Jenkins master and two agents.
The setup is installed and run in a Vagrant image.
Run the following in the root of the repository
# Spin up the Vagrant VM
$ vagrant up
# Once finished, ssh into VM
$ vagrant ssh- Go into the directory that has the repository files
$ cd /opt/provisioning/- Load ENVIRONMENT VARIABLES:
$ source env/vars.sh- Prepare directories and permissions
# Permissions on /var/run/docker.sock
$ sudo chmod 666 /var/run/docker.sock
# Directory for Jenkins home
$ mkdir -p ~/jenkins_home
$ chmod -R 777 ~/jenkins_home- Build the custom Jenkins Docker image
# Build Jenkins Docker Image
$ docker-compose -f env/docker-compose-jenkins.yml build- Create custom Jenkins network (where master and agents will live in harmony)
$ docker network create jenkins_network- Start the Jenkins master
$ docker-compose -f env/docker-compose-jenkins.yml up -d- Browse to http://192.168.0.20:8080 and complete the initial setup wizard
- Get initial admin password from
docker logs jenkins-masteroutput - Install suggested plugins
- Install the Docker Slaves Plugin (for dynamic Docker agent provisioning per build)
- Install the Blue Ocean plugin (recommended)
- Define two Jenkins agents (slaves)
- Create two nodes from the
Manage Jenkins->Manage Nodes - Call the nodes
agent1andagent2 - Set remote root directory to
/home/jenkins - Configure them to
Launch method->Launch agent via Java Web Start - Get the secret token for each node (AGENT1_TOKEN and AGENT2_TOKEN)
- Provide token in
env/vars.shfile - Reload ENVIRONMENT VARIABLES:
$ source env/vars.sh - Get initial admin password from
Once you have the tokens for the agents, start the two agents
$ docker-compose -f env/docker-compose-agents.yml up -dYou can create a Pipeline type job using any of the provided examples in the different directories
Known bug for Docker Slaves Plugin
java.io.IOException: Failed to create docker imageHow to solve:
Manage Jenkins -> Configure System -> Docker Slaves -> Remoting image should be jenkins/slave