This sample walks through the process of starting up an OpenShift cluster and deploying a Jenkins Pod in it. It also configures a simple application and then creates a Jenkins job to trigger a build of that application.
The Jenkins job will trigger OpenShift to build+deploy a test version of the application, validate that the deployment works, and then tag the test version into production.
-
Follow steps 1-7 from the sample-app
At this point you should be logged in to openshift as a normal user and working with a project named
test. -
Add the
editrole to thedefaultservice account in thetestproject:$ oc policy add-role-to-user edit system:serviceaccount:test:defaultThis will allow the service account Jenkins uses to run builds and tag images.
-
Optional: If you are going to run Jenkins somewhere other than as a deployment within your same project you will need to provide an access token to Jenkins to access your project.
-
Identify the service account token secret:
$ oc describe serviceaccount defaultExample output:
Name: default Labels: <none> Secrets: { default-token-uyswp } { default-dockercfg-xcr3d } Tokens: default-token-izv1u default-token-uyswpIn this case the secret name is
default-token-uyswp -
Retrieve the token from the secret:
$ oc describe secret <secret name from above> # e.g. default-token-izv1uExample output:
Name: default-token-izv1u Labels: <none> Annotations: kubernetes.io/service-account.name=default,kubernetes.io/service-account.uid=32f5b661-2a8f-11e5-9528-3c970e3bf0b7 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1066 bytes token: eyJhbGc..<content cut>....wRACopy the value from the
tokenfield, it will be used later.
-
-
Create and deploy the Jenkins service
$ oc new-app jenkins-ephemeral-template.jsonNote: This template uses an EmptyDir type volume. If you want to ensure your jenkins configuration/job information is persisted through pod restarts and deployments, you can use the jenkins-persistent-template.json template file which uses a persistent volume but requires additional PersistentVolume setup.
-
Retrieve the ip and port of the jenkins service that was just created:
$ oc get svc jenkinsNote the ip and port of the Jenkins service reported by the second command, you will need it later.
-
Create the sample application configuration
$ oc new-app application-template.json -
Open the Jenkins service ip:port from step 5 in your browser. Once it is available, login using username
adminand passwordpassword. -
Select the the
OpenShift Samplejob and clickConfigure. You'll see a series of Jenkins build steps defined. These build steps are from the Jenkins plugin for V3 Openshift. Read about the OpenShift Jenkins plugin for details on the various functionality provided. The default values for each of the various build steps listed for the sample job should work as is. You can save your changes to the job, clickBuildand skip to step 11. -
Optional (if the default values are no longer applicable based on how your OpenShift environment was constructed): change the settings for each build step as needed. For example, update the "URL of the OpenShift api endpoint" field with
https://hostname:portwhere hostname/ip and port are for your OpenShift api endpoint, or update the "The authorization token for interacting with OpenShift" field with the token value retrieved in step 3. You can save your changes to the job, clickBuildand skip to step 12. -
Optional (if you would like to set the build step fields via Jenkins build parameters): Set any given build step field with the name of the build parameter you will specify. Then check
This build is parameterizedand add String parameters, defining those build parameters. The README for the OpenShift Jenkins plugin has an example for doing this with screenshots. -
Save your changes to the job and click
Build with Parametersand thenBuild. -
Watch the job output
It will trigger an OpenShift build of the application, wait for the build to result in a deployment, confirm the new deployment works, and then tag the image for production. This tagging will trigger another deployment, this time creating/updating the production service.
-
Confirm both the test and production services are available by browsing to both services:
$ oc get services -n test | grep frontend
If you run into difficulties running OpenShift or getting the OpenShift Sample job to complete successfully, start by reading through the troubleshooting guide.