diff --git a/test/jenkins/README.md b/test/jenkins/README.md index 0874a67..e34f9f7 100644 --- a/test/jenkins/README.md +++ b/test/jenkins/README.md @@ -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 \ No newline at end of file +- `kubectl cluster-info`: Retrieve information about the Kubernetes cluster, including the Kubernetes control plane address (e.g., https://kubernetes.docker.internal:6443). \ No newline at end of file diff --git a/test/jenkins/install.sh b/test/jenkins/install.sh index 7e0e044..cccf451 100755 --- a/test/jenkins/install.sh +++ b/test/jenkins/install.sh @@ -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//${TOKEN}/g" "${JENKINS_INSTALLATION_CONFIG}/secrets-template.properties" > "${JENKINS_INSTALLATION_CONFIG}/secrets.properties" }