Skip to content

Commit

Permalink
Jenkins as code example to autostart jenkins workers as nomad batch j…
Browse files Browse the repository at this point in the history
…obs (#82)

* importing minimal jasc setup for nomad jenkins workers
* fix: general cleanup

Signed-off-by: Bram Vogelaar <[email protected]>
  • Loading branch information
attachmentgenie authored Feb 23, 2024
1 parent 16c567d commit e75e53c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packs/jenkins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ This pack contains all you need to deploy jenkins (version 2 by default) in Noma
## Jenkins Environment Variables

You can pass the right environment variables to Jenkins.
An example of the `docker_jenkins_env_vars` to use is in the `vars.nomad` file.
An example of the `docker_jenkins_env_vars` to use is in the `examples/vars.nomad` file.

## Jenkins as Code

An example as to how the `configuration-as-code` plugin can be used to create and configure jenkins is in the `vars_jasc.nomad` file.
An example as to how use the `configuration-as-code` plugin can be used to create and configure jenkins is in the `examples/vars_jasc.nomad` file.

## Nomad Job Runners

An example as to how the `nomad` plugin can be used to create and configure autoscaling jenkins workers in nomad itself is in the `examples/vars_cloud.nomad` file.
File renamed without changes.
79 changes: 79 additions & 0 deletions packs/jenkins/examples/vars_cloud.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
docker_jenkins_env_vars = {
"java_opts": "-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false",
}
jasc_config = <<EOF
jenkins:
agentProtocols:
- "JNLP4-connect"
- "Ping"
clouds:
- nomad:
name: "nomad"
nomadUrl: "http://{{ env "attr.unique.network.ip-address" }}:4646"
prune: true
templates:
- idleTerminationInMinutes: 10
jobTemplate: |-
{
"Job": {
"Region": "global",
"ID": "%WORKER_NAME%",
"Type": "batch",
"Datacenters": [
"dc1"
],
"TaskGroups": [
{
"Name": "jenkins-worker-taskgroup",
"Count": 1,
"RestartPolicy": {
"Attempts": 0,
"Interval": 10000000000,
"Mode": "fail",
"Delay": 1000000000
},
"Tasks": [
{
"Name": "jenkins-worker",
"Driver": "docker",
"Config": {
"image": "jenkins/inbound-agent"
},
"Env": {
"JENKINS_URL": "http://{{ env "NOMAD_ADDR_http" }}",
"JENKINS_AGENT_NAME": "%WORKER_NAME%",
"JENKINS_SECRET": "%WORKER_SECRET%",
"JENKINS_TUNNEL": "{{ env "NOMAD_ADDR_jnlp" }}"
},
"Resources": {
"CPU": 500,
"MemoryMB": 256
}
}
],
"EphemeralDisk": {
"SizeMB": 300
}
}
]
}
}
labels: "nomad"
numExecutors: 1
prefix: "jenkins"
reusable: true
tlsEnabled: false
workerTimeout: 1
numExecutors: 0
jobs:
- script: >
job('nomad') {
label('nomad')
steps {
shell('whoami')
}
}
EOF
plugins = ["configuration-as-code", "hashicorp-vault-plugin", "job-dsl", "nomad"]
register_consul_service = true
volume_name = "jenkins"
File renamed without changes.
5 changes: 5 additions & 0 deletions packs/jenkins/templates/jenkins.nomad.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ EOF
destination = "local/plugins.txt"
change_mode = "noop"
}

resources {
cpu = [[ .jenkins.task_resources.cpu ]]
memory = [[ .jenkins.task_resources.memory ]]
}
}
[[- end ]]

Expand Down

0 comments on commit e75e53c

Please sign in to comment.