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.
The following types of credentials are supported and can be used to authenticate against Kubernetes clusters:
- Username and Password (see Credentials plugin)
- Certificates (see Credentials plugin)
- Token, as secrets (see Plain Credentials plugin)
- OpenShift tokens, as secrets (see Kubernetes Credentials plugin)
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.
The arguments to the withKubeConfig
step are:
credentialsId
- the Jenkins identifier of the credentials to use.caCertificate
- an optional base64-encoded 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
Example:
node {
stage('List pods') {
withKubeConfig([credentialsId: '<credential-id>', caCertificate: '<ca-certificate>', serverUrl: '<api-server-address>']) {
sh 'kubectl get pods'
}
}
}
In Jenkins > job name > Configure > Build Environment
Brief description of the named fields:
- credentialsId - the Jenkins identifier of the credentials to use.
- caCertificate - an optional base64-encoded certificate to check the Kubernetes api server's against
- serverUrl - the url of the api server
Please file bug reports directly on the Jenkins issue tracker
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