https://github.com/eldada/jenkins-pipelines-examples
Keep a few examples of Jenkins Pipelines
https://github.com/eldada/jenkins-pipelines-examples
Last synced: 4 months ago
JSON representation
Keep a few examples of Jenkins Pipelines
- Host: GitHub
- URL: https://github.com/eldada/jenkins-pipelines-examples
- Owner: eldada
- Created: 2017-07-05T06:47:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T07:01:54.000Z (almost 9 years ago)
- Last Synced: 2025-03-30T09:21:25.634Z (over 1 year ago)
- Language: Groovy
- Size: 18.6 KB
- Stars: 16
- Watchers: 1
- Forks: 45
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jenkins Pipelines Examples
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.**
## Setup Local Jenkins
These examples assume a simple setup of a single Jenkins master and two agents.
The setup is installed and run in a [Vagrant](https://www.vagrantup.com/) image.
### Spin up the Vagrant VM
Run the following in the root of the repository
```bash
# Spin up the Vagrant VM
$ vagrant up
# Once finished, ssh into VM
$ vagrant ssh
```
### Start a local Jenkins master
- Build the custom Jenkins Docker image
```bash
# Go into the directory that has the repository files
$ cd /opt/provisioning/
# Build the Jenkins Docker image
$ docker build -t jenkinsx:1 -f jenkins/Dockerfile .
```
- Prepare directories and permissions
```bash
# 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
```
- Start the Jenkins master
```bash
$ docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v ~/jenkins_home:/var/jenkins_home jenkinsx:1
```
- Browse to http://192.168.17.17:8080 and complete the initial setup wizard
- Get initial admin password from `docker logs jenkins` output
- 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 `agent1` and `agent2`
- 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**)
### Start two Jenkins agents (slaves)
Once you have the tokens for the agents, start the two agents
```bash
# Start agent 1
$ docker run -d --link jenkins:jenkins-server --name agent1 jenkinsci/jnlp-slave:3.7-1 -url http://jenkins-server:8080 ${AGENT1_TOKEN} agent1
# Start agent 2
$ docker run -d --link jenkins:jenkins-server --name agent2 jenkinsci/jnlp-slave:3.7-1 -url http://jenkins-server:8080 ${AGENT2_TOKEN} agent2
```
### Create Pipeline jobs
You can create a Pipeline type job using any of the provided examples in the different directories