The CloudBees OpenShift CLI plugin provisions the OpenShift CLI in your CloudBees CI jobs so that you can deploy applications or interact with an OpenShift environment.
Global configuration
OpenShift CLI installations can be configured from tar.gz
archive from a custom location.
Job configuration
To enable the OpenShift CLI in a job, goto the Configuration page of the job and, in the Build Environment section, check Setup OpenShift CLI.
You can then select CLI installation:: OpenShift CLI installation to use. CLI can be configured for automatic installation on executor, please read next section.
- OpenShift controller URL
-
URL for the OpenShift controller endpoint URL.
- Insecure
-
Checking this option will disable the SSL certificate validation, so can be used to connect to an OpenShift controller which uses a self-signed HTTPS certificate. Please note this option introduce security risks and should not be used for production environments.
- Credentials
-
OpenShift credentials to setup so build steps within this job will run within an authenticated context.
Once the OpenShift CLI is setup in a job, you can use it in any Execute Shell or Execute Windows Batch Command step.
Using the OpenShift CLI in a Pipeline job
Once the OpenShift CLI is setup in the System Configuration, you can use it in any Pipeline job as a build wrapper.
OpenShift CLI Pipeline syntax
The Groovy syntax looks like:
node { // ... wrap([$class: 'OpenShiftBuildWrapper', (1) installation: 'oc (latest)', (2) url: 'https://openshift.example.com:8443', (3) insecure: true, (4) credentialsId: 'openshift-credentials']) { (5) sh 'oc scale --replicas=3 replicationcontrollers webapp' (6) } }
1 | "General Build Wrapper" step for a OpenShiftBuildWrapper |
2 | Name of the OpenShift CLI version defined in the System Configuration screen |
3 | URL of the OpenShift controller endpoint (e.g. "https://openshift.example.com:8443") |
4 | Skip SSL validation when using a self signed certificate for the API endpoint (please don’t) |
5 | ID of the credentials to configure the OpenShift CLI |
6 | oc commands used in sh steps, the OpenShift CLI is configured with the desired API endpoint and credentials. |
Evaluating oc
commands result
Evaluating the result of the oc
command is key to the logic of your Pipeline.
-
oc
commands return non zero exit code in case of error and thus, shell steps will by default fail if anoc
command fails -
To capture the output of an
oc
command in a Pipeline, usereturnStdout: true
as described in the Pipeline steps reference.