Jenkins controller container image based on configuration as code
The Jenkins configuration is stored in casc.yaml
Example of how to run in docker:
docker run -d --name jenkins -e JENKINS_HOST_URL="http://localhost:8080" -e JENKINS_ADMIN_USER=admin -e JENKINS_ADMIN_PASSWORD="password" -e GITHUB_USER="[email protected]" -e GITHUB_PK="..." -p 8080:8080 -p 50000:50000 renezubcevic/jenkins-controller
You can build a local custom version in two steps.
-
build the base image with adjusted plugins
docker build -t renezubcevic/jenkins-casc -f Dockerfile-casc .
-
build the controller with a custom casc.yaml file and custom footer
docker build --build-arg JENKINS_FOOTER_URL="https://www.zubcevic.com" -t renezubcevic/jenkins-controller -f Dockerfile .
def pluginList = new ArrayList(Jenkins.instance.pluginManager.plugins)
pluginList.sort {it.getShortName() }.each{
plugin ->
println("${plugin.getShortName()}:${plugin.getVersion()}")
}
curl 'localhost:8080/jnlpJars/jenkins-cli.jar' > jenkins-cli.jar
java -jar jenkins-cli.jar -s http://admin:password@localhost:8080 groovy = < pluginEnumerator.groovy | sort > plugins-installed.txt
The most essential plugin for configuration as code to work.
Used in order to test my Jenkins templating engine pipeline. Added here to see how to configure the global settings as code.
Used to auto install Java SDK from AdoptOpenJDK. Just required for my own sample job. Referred to in casc.yaml as:
tool:
jdk:
installations:
- name: "JDK11"
properties:
- installSource:
installers:
- adoptOpenJdkInstaller:
id: "jdk-11.0.9.1+1"
curl -X GET http://admin:[email protected]:8080/job/TestMB/credentials/store/folder/domain/_/credential/jenkins-id/config.xml -o jenkinssecret.xml
curl -X GET http://admin:[email protected]:8080/job/TestMB/credentials/store/folder/domain/_/credential/github-id/config.xml -o githubsecret.xml
curl -X GET http://admin:[email protected]:8080/job/TestMB/config.xml -o jobconfig.xml
JENKINS_CRUMB=$(curl --cookie-jar tmpCookie 'http://admin:[email protected]:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
curl --cookie tmpCookie -X POST 'http://admin:[email protected]:8080/createItem?name=TestMB' -d @jobconfig.xml -H "$JENKINS_CRUMB" -H "Content-Type: text/xml"
curl --cookie tmpCookie -X POST 'http://admin:[email protected]:8080/job/TestMB/build?delay=0' -H "$JENKINS_CRUMB"
curl --cookie tmpCookie -X POST 'http://admin:[email protected]:8080/job/TestMB/job/develop/build?delay=0' -H "$JENKINS_CRUMB"
Use external secrets provider: