OpenShift CLI Plugin

The OpenShift command line interface (CLI) plugin provisions the os CLI in your Jenkins jobs so that you can deploy applications or interact with an OpenShift environment.

Global Configuration

OpenShift CLI installations can be configured from Jenkins  Manage Jenkins  Configure System. The default installer downloads the OpenShift CLI and installs it on the agent the first time it’s used by a job. Alternatively, you can configure a custom installer to download a 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 master URL

URL for the OpenShift master endpoint URL.

Insecure

Checking this option will disable the SSL certificate validation, so can be used to connect to an OpenShift master 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.

job config
Figure 1. OpenShift CLI job configuration

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 Jenkins System Configuration screen
3 URL of the OpenShift Master 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 an oc command fails

  • To capture the output of an oc command in a Pipeline, use returnStdout: true as described in the Pipeline steps reference.

Pipeline snippet generator

You can generate the Pipeline statement to setup the OpenShift CLI using the Jenkins Pipeline Snippet Generator.

workflow snippet
Figure 2. OpenShift CLI Pipeline snippet
Copyright © 2010-2020 CloudBees, Inc.Online version published by CloudBees, Inc. under the Creative Commons Attribution-ShareAlike 4.0 license.CloudBees and CloudBees DevOptics are registered trademarks and CloudBees Core, CloudBees Flow, CloudBees Flow Deploy, CloudBees Flow DevOps Insight, CloudBees Flow DevOps Foresight, CloudBees Flow Release, CloudBees Accelerator, CloudBees Accelerator ElectricInsight, CloudBees Accelerator Electric Make, CloudBees CodeShip, CloudBees Jenkins Enterprise, CloudBees Jenkins Platform, CloudBees Jenkins Operations Center, and DEV@cloud are trademarks of CloudBees, Inc. Most CloudBees products are commonly referred to by their short names — Accelerator, Automation Platform, Flow, Deploy, Foresight, Release, Insight, and eMake — throughout various types of CloudBees product-specific documentation. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Jenkins is a registered trademark of the non-profit Software in the Public Interest organization. Used with permission. See here for more info about the Jenkins project. The registered trademark Jenkins® is used pursuant to a sublicense from the Jenkins project and Software in the Public Interest, Inc. Read more at www.cloudbees.com/jenkins/about. Apache, Apache Ant, Apache Maven, Ant and Maven are trademarks of The Apache Software Foundation. Used with permission. No endorsement by The Apache Software Foundation is implied by the use of these marks.Other names may be trademarks of their respective owners. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this content, and CloudBees was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this content, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.