Am opionionated configuration of jenkins designed for stateless usage.
4.0K
Stateless jenkins is a dockerized configuration of jenkins that is intended to be 100% stateless. i.e. volume persistence is not required.
Jenkins will automatically create jobs by scanning the root repository for Jenkinsfile or jobs.groovy dsl files.
e.g.
/etc/jenkins/keys/ssh-private will be added to a SSH credential called deploy. The public portion of this key should be loaded on Github / Bitbucket as a deploy key allowing Jenkins read only access to the repository.jobs.groovy if found in the root of the repository will be executedJenkinsfile's - A new project will be created for each file found with the name of the containing folder and configured to poll for changes in that folder only. This allows different jobs to run for changes found in different directories.Jenkins installed to: /usr/share/jenkins
| Environment Var | Required | Description |
|---|---|---|
| REPO | Yes | Git checkout path of the job repository |
| DEPLOY_KEY | No | Path to SSH deploy private key, can be referenced in jobs using deploy credential id. defaults to /etc/jenkins/keys/ssh-private |
| URL | Yes | Public URL that the jenkins is accessible at |
| Yes | Git / Notifications email | |
| JENKINS_PASSWORD | No | admin user password, defaults to admin |
| API_USER | No | Can be referenced in jobs using api credential id. |
| API_PASS | No | |
| JAVA_OPTS | No | JVM Arguments |
| JENKINS_OPTS | No | JVM Arguments |
| JENKINS_SLAVE_AGENT_PORT | No | Defaults to 50001 |
| LDAP_SERVER | ||
| LDAP_USER | ||
| LDAP_PASS | ||
| LDAP_ROOT_DN | ||
| AD_SERVER | ||
| AD_DOMAIN | ||
| AD_SITE | ||
| AD_USER | ||
| AD_PASS | ||
| READ_GROUP | authenticated | |
| ADMIN_GROUP | Jenkins Admins |
Run a docker container mapping the keys into the container using a volume:
docker run -p 8080:8080 -e [email protected]/org/jenkins-jobs.git -e DEPLOY_KEY=/etc/jenkins/keys/ssh-private -v $PWD/ssh-private/ssh-keys:/etc/jenkins/keys/ssh-private --privileged --rm jenkins
Create or import a Kubernetes SSH secret:
kubectl create secret generic deploy-key --from-file=ssh-private=~/.ssh/id_rsa
Mount the SSH keys as a volume
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
template:
metadata:
labels:
app: jenkins
spec:
securityContext:
privileged: true
containers:
- env:
- name: REPO
value: [email protected]/org/jenkins-jobs.git
image: jenkinsci/jenkins:lts
imagePullPolicy: Always
name: jenkins
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- mountPath: /etc/jenkins/keys/
name: deploy-keys
volumes:
- name: deploy-key
secret:
secretName: deploy-key
def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
plugins.each {
version = it.getVersion()
if (it.getUpdateInfo() != null) {
version = it.getUpdateInfo().version
}
println "${it.getShortName()}:${version}"
}
Content type
Image
Digest
Size
1.6 GB
Last updated
about 6 years ago
docker pull moshloop/stateless-jenkins