Skip to content

Commit

Permalink
ref(12): Jenkins on Docker and CasC configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanjerome committed Aug 14, 2023
1 parent 16542d8 commit 6f6b222
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
72 changes: 65 additions & 7 deletions test/jenkins/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,70 @@
# Automate Jenkins Installation on Docker for Testing
# Automated Jenkins Installation on Docker for Testing with Kubernetes Integration

## Prerequisites

- Docker must be installed.
- Kubernetes must be installed.

## Installation

To set up a new Jenkins instance, execute the following command:
```bash
./test/jenkins/install.sh
```

## Testing

Follow these steps to test the Kubernetes integration:

1. Create a pipeline named `test-kubernetes-agent`.
2. Insert the provided pipeline definition script:

```groovy
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:alpine
command:
- cat
tty: true
- name: node
image: node:16-alpine3.12
command:
- cat
tty: true
'''
}
}
stages {
stage('Run maven') {
steps {
container('maven') {
sh 'mvn -version'
}
container('node') {
sh 'npm version'
}
}
}
}
}
```

3. Execute the pipeline; two agents should be deployed on the Kubernetes cluster.

## References

- https://www.digitalocean.com/community/tutorials/how-to-automate-jenkins-setup-with-docker-and-jenkins-configuration-as-code
- https://github.com/abrahamNtd/poc-jenkins-jcasc
- https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos
- https://www.youtube.com/watch?v=ZXaorni-icg
- [Automating Jenkins Setup with Docker and Jenkins Configuration as Code](https://www.digitalocean.com/community/tutorials/how-to-automate-jenkins-setup-with-docker-and-jenkins-configuration-as-code)
- [GitHub - Jenkins Configuration as Code Plugin Demos](https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos)
- [YouTube - Automated Jenkins Setup using Docker and Configuration as Code](https://www.youtube.com/watch?v=ZXaorni-icg)
- [GitHub Gist - Kubernetes Cluster Info Command](https://gist.github.com/darinpope/67c297b3ccc04c17991b22e1422df45a)

## Commands
## Useful Commands

- `kubectl cluster-info`: get infos on kubernetes cluster almost the Kubernetes control plane address: https://kubernetes.docker.internal:6443
- `kubectl cluster-info`: Retrieve information about the Kubernetes cluster, including the Kubernetes control plane address (e.g., https://kubernetes.docker.internal:6443).
5 changes: 3 additions & 2 deletions test/jenkins/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ set -euo pipefail
install::_configure_kubernetes() {
declare -r name="jenkins"

kubectl delete namespace "${name}"
kubectl delete namespace "${name}" || true

kubectl create namespace "${name}"
kubectl create serviceaccount "${name}" --namespace="${name}"
kubectl create token "${name}" --namespace="${name}"
kubectl create rolebinding "${name}"-admin-binding --clusterrole=admin --serviceaccount="${name}":"${name}" --namespace="${name}"

local TOKEN=$(kubectl create token "${name}" --namespace="${name}")
local TOKEN
TOKEN=$(kubectl create token "${name}" --namespace="${name}")
sed "s/<SERVICE_ACCOUNT_TOKEN>/${TOKEN}/g" "${JENKINS_INSTALLATION_CONFIG}/secrets-template.properties" > "${JENKINS_INSTALLATION_CONFIG}/secrets.properties"
}

Expand Down

0 comments on commit 6f6b222

Please sign in to comment.