Skip to end of metadata
Go to start of metadata

travis-ci coveralls

Allows you to configure kubectl in your job to interact with Kubernetes clusters. Any tool built on top of kubectl can then be used from your pipelines, e.g. kubernetes-deploy to perform deployments.

Initially extracted and rewritten from the Kubernetes Plugin.

Prerequisites

  • An executor with kubectl installed (tested against v1.8 to v1.12 included)
  • A Kubernetes cluster

Supported credentials

The following types of credentials are supported and can be used to authenticate against Kubernetes clusters:

Quick usage guide

Pipeline usage

The kubernetes-cli plugin provides the function withKubeConfig() for Jenkins Pipeline support. You can go to the Snippet Generator page under Pipeline Syntax section in Jenkins, select withKubeConfig: Setup Kubernetes CLI from the Sample Step dropdown, and it will provide you configuration interface for the plugin. After filling the entries and click Generate Pipeline Script button, you will get the sample scripts which can be used in your Pipeline definition.

Example:

node {
  stage('List pods') {
    withKubeConfig([credentialsId: '<credential-id>',
                    caCertificate: '<ca-certificate>',
                    serverUrl: '<api-server-address>',
                    contextName: '<context-name>'
                    ]) {
      sh 'kubectl get pods'
    }
  }
}

The arguments to the withKubeConfig step are:

  • credentialsId - the Jenkins identifier of the credentials to use.
  • caCertificate - an optional certificate to check the Kubernetes api server's against. If you don't specify one, the CA verification will be skipped.
  • serverUrl - the url of the api server
  • contextName - name of the context to create or to switch to if a raw kubeconfig was provided

From the web interface

  1. Within the Jenkins dashboard, select a Job and then select Configure
  2. Scroll down and click the "Add build step" dropdown
  3. Select "Configure Kubernetes CLI (kubectl)"
  4. In the "Credential" dropdown, select the credentials to authenticate on the cluster or the kubeconfig stored in Jenkins.

webui

Brief description of the named fields:

  • credentialsId - the Jenkins identifier of the credentials to use.
  • caCertificate - an optional certificate to check the Kubernetes api server's against
  • serverUrl - the url of the api server
  • contextName - name of the context to create or to switch to if a raw kubeconfig was provided

Reporting an issue

Please file bug reports directly on the Jenkins issue tracker

Building and Testing

To build the extension, run:

mvn clean package

and upload target/kubernetes-cli.hpi to your Jenkins installation.

To run the tests:

mvn clean test

Release

mvn release:prepare release:perform


Releases

Refer to the CHANGELOG in the plugin repository

Support

Comment section

Please do not use the comment section for support questions but fill a JIRA ticket instead. Comments should only be related to the content of this page.